5.5.1. Direct loading with MOV and MVN

In ARM state, you can use the MOV and MVN instructions to load a range of 8-bit constant values directly into a register:

In addition, you can use either MOV or MVN in conjunction with the barrel shifter to generate a wider range of constants. The barrel shifter can right rotate 8-bit values through any even number of positions from 2 to 30.

You can use MOV to load values that follow the pattern shown in Table 5.4, in a single instruction. Use MVN to load the bitwise complement of these values. Right rotates by 2, 4, or 6 bits produce bit patterns with a few bits at each end of a 32-bit word.

Table 5.4. ARM state immediate constants

Decimal valuesEquivalent HexadecimalStep between valuesRotate
0-2550-0xff1No rotate
256, 260, 264, ... , 10200x100-0x3fc4Right by 30 bits
1024, 1040, 1056, ... , 40800x400-0xff016Right by 28 bits
4096, 4160, 4224, ... , 163200x1000-0x3fc064Right by 26 bits
64 x 224, 65 x 224, ... , 255 x 2240x40000000-0xff000000224Right by 8 bits
4 x 224, ... , 252 x 224 + 30x4000000-0xfc000003226, 1Right by 6 bits
16 x 224, ... , 240 x 224 + 150x10000000-0xf000000f228, 1Right by 4 bits
64 x 224, ... , 192 x 224 + 630x40000000-0xc000003f230, 1Right by 2 bits

Using MOV and MVN

You do not need to work out how to load a constant using MOV or MVN. The assembler attempts to convert any constant value to an acceptable form.

This means that you can use MOV and MVN in two ways:

  • Convert the value to an 8-bit constant, followed by the rotate right value. For example:

    	MOV 		r0, #0xFF,30					; r0 = 1020
  • Allow the assembler to do the work of converting the value. If you specify the constant to be loaded, the assembler converts it to an acceptable form if possible. For example:

    	MOV		r0, #0x3FC					; r0 = 1020

    If the constant cannot be expressed as a right rotated 8-bit value or its bitwise complement, the assembler reports an error.

Table 5.5 gives an example of how the assembler converts constants. The left-hand column lists the ARM instructions input to the assembler. The right-hand column shows the instruction generated by the assembler.

Table 5.5. Assembler generated constants

Input instructionAssembled equivalent
MOV r0, #0MOV r0, #0
MOV r1, #0xFF000000MOV r1, #0xFF, 8
MOV r2, #0xFFFFFFFFMVN r2, #0
MVN r3, #1MVN r3, #1
MOV r4, #0xFC000003MOV r4, #0xFF, 6
MOV r5, #0x03FFFFFCMVN r5, #0xFF, 6
MOV r6, #0x55555555Error (cannot be constructed)

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 generates an error message.

Copyright © 1997, 1998 ARM Limited. All rights reserved.ARM DUI 0040D