We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi,
I find Arm has 16 bit immediate value load to register instruction, but it has no instruction to load 32 bit value to register. I am new to asm level programming. How many ways to load a register to a desired value for an Arm CPU?
thanks,
As ARM instructions are 32-bits the short answer is "you can't"
However, one of the best options is to use the format:
LDR Rn, =<constant>
The assembler will then work out whether it can use a MOV, MVN or LDR from a literal pool,
for example:
LDR R0, =0xFFFF43FF
should resolve to
MVN R0, #0xBC00
If the value can't be resolved this way, then it will use a relative load from a literal pool, e.g.
LDR Rn, [pc, #<offset>]
DCD <constant>
This blog may be useful:
How to Load Constants in Assembly for ARM Architecture
In particular it shows how to use MOVW and MOVT to load two 16-bit constants from the instruction steam, which is often a better solution that a literal load (which pollutes the D-Cache).