I would like to do the following operation in ARM assembly with only 24 bytes of code/data. Is it possible?
PC = [MEMLOC] + PC
Or, put into words, I would like to jump ahead based on a PC-relative offset which is read from memory.
The value read from MEMLOC must be a full 32-bit word
I can do this easily with 16 [<-updated from 32 before] bytes (using standard LDR and ADD instructions), but looking to optimize away one instruction. Anyone know if this is possible? I think there are ways to do with a ~20 bit word read from memory, but it may not be possible with a full 32-bit word.
Update: Here is what I have:
LDR R12, =MEMLOC1
ADD R12, PC, R12
LDR PC, [R12]
MEMLOC1: (contains 32-bit word)
Your solution actually takes 36 bytes because the first ldr probably causes a memory pool entry containing the address of MEMLOC1 to be generated in your text (unless your linker is smart enough to fix that).
In 24 bytes you can do this by moving your data closer so that you can generate a pc-relative address.
The offset might need to be minus a few bytes to compensate for the incremented pc.