Re:ARM immediate value encoding (2014)
by gpvos on Tuesday January 30, 2018 @02:26PM
(#16268155)
If I understand correctly, for some values that would take four instructions.
[ Parent
| on HN ]
Re:ARM immediate value encoding (2014)
by jhawthorn on Tuesday January 30, 2018 @02:37PM
(#16268260)
You would use the LDR instruction to load the word from RAM. So just one instruction, but with some slower memory access.
When writing ARM assembly, the assembler (at least the ones I've seen) abstract this detail away from you.
You can use
ldr r0, =0xff000000
and the assembler will emit a MOV if it can, and if it can't it will put the value somewhere in RAM and use LDR to load it up.ARM is fun.
Modern ARM actually has a 16-bit immediate version of MOV, plus MOVT which is the same but moves to the top 16 bits of a register. With a pair of those, you can load any 32-bit value in 2 instructions, without polluting the data cache like you would with LDR [pc+offset].