ARM VERSION 1.2 Computer Hardware User Manual


 
Writing ARM and Thumb Assembly Language
ARM DUI 0068B Copyright © 2000, 2001 ARM Limited. All rights reserved. 2-27
Direct loading with MOV in Thumb state
In Thumb state you can use the
MOV
instruction to load constants in the range 0-255. You
cannot generate constants outside this range because:
The Thumb
MOV
instruction does not provide inline access to the barrel shifter.
Constants cannot be right-rotated as they can in ARM state.
The Thumb
MVN
instruction can act only on registers and not on constant values.
Bitwise complements cannot be directly loaded as they can in ARM state.
If you attempt to use a
MOV
instruction with a value outside the range 0-255, the
assembler reports the error:
Immediate n out of range for this operation
.
2.6.2 Loading with LDR Rd, =const
The
LDR Rd,=const
pseudo-instruction can construct any 32-bit numeric constant in a
single instruction. Use this pseudo-instruction to generate constants that are out of range
of the
MOV
and
MVN
instructions.
The
LDR
pseudo-instruction generates the most efficient code for a specific constant:
If the constant can be constructed with a
MOV
or
MVN
instruction, the assembler
generates the appropriate instruction.
If the constant cannot be constructed with a
MOV
or
MVN
instruction, the assembler:
places the value in a literal pool (a portion of memory embedded in the code
to hold constant values)
generates an
LDR
instruction with a program-relative address that reads the
constant from the literal pool.
For example:
LDR rn, [pc, #offset to literal pool]
; load register n with one word
; from the address [pc + offset]
You must ensure that there is a literal pool within range of the
LDR
instruction
generated by the assembler. Refer to Placing literal pools on page 2-28 for more
information.
Refer to LDR ARM pseudo-instruction on page 4-82 for a description of the syntax of
the
LDR
pseudo-instruction.