Immediate Values
Immediate Values
Explain this picture:
The 4-bit rotate value stored in bits 11-8 is multiplied by two giving a range of 0-30 in steps of two.
What can we express and not express using this scheme?
Using this scheme we can express immediate constants such as:
0x000000FF0x00000FF00xFF0000000xF000000FBut immediate constants such as:
0x000001FE0xF000F0000x55550000…are not possible.
An assembler will convert ___ values to the rotated form. Impossible values will cause an error.
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 ___ instead of MOV to form the bitwise complement of the required constant. For example the impossible instruction MOV r0,#0xFFFFFFFF could be assembled as___ r0,#0.
Some assemblers will use other tricks such as using MVN instead of MOV to form the bitwise complement of the required constant. For example the impossible instruction MOV r0,#0xFFFFFFFF could be assembled as MVN r0,#0.
Remarks
The impact of this is that some constants are “ARM ______”. Some are not. Study of the numbers you’re using can sometimes reveal scope for optimisation.
Remarks
The impact of this is that some constants are “ARM friendly”. Some are not. Study of the numbers you’re using can sometimes reveal scope for optimisation.
Loading Wide Values
What does this code do?
MOV r2, #0x55 ; R2 = 0x00000055 ORR r2, r2, r2, LSL #8 ; R2 = 0x00005555 ORR r2, r2, r2, LSL #16 ; R2 = 0x55555555
What does this code do?
LDR r2, =0x55555555
What does this LDR Rx,=const do?
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
The pseudo-instruction LDR Rx,=const tries to form the constant in a single instruction, if possible, otherwise it will generate an LDR.