You can’t fit an arbitrary 32-bit value into a 32-bit instruction word. ARM data processing instructions have 12 bits of space for values in their instruction word. This is arranged as a four-bit rotate value and an eight-bit immediate value:
The 4-bit rotate value stored in bits 11-8 is multiplied by two giving a range of 0-30 in steps of two.
Using this scheme we can express immediate constants such as:
But immediate constants such as:
...are not possible.
An assembler will convert big values to the rotated form. Impossible values will cause an error.
Some assemblers will use other tricks such as using
MOV to form the bitwise complement of the required
constant. For example the impossible instruction
r0,#0xFFFFFFFF could be assembled as
Loading Wide Values
You can form constants wider than those available in a single instruction by using a sequence of instructions to build up the constant. For example:
MOV r2, #0x55 ; R2 = 0x00000055 ORR r2, r2, r2, LSL #8 ; R2 = 0x00005555 ORR r2, r2, r2, LSL #16 ; R2 = 0x55555555
...or load the value from memory:
LDR r2, =0x55555555
LDR Rx,=const tries to form the
constant in a single instruction, if possible, otherwise it will generate