
ARM Instruction Set - Shifts
ARM7TDMI Data Sheet
ARM DDI 0029E
4-12
O
The arithmetic operations (SUB, RSB, ADD, ADC, SBC, RSC, CMP, CMN) treat each
operand as a 32 bit integer (either unsigned or 2's complement signed, the two are
equivalent). If the S bit is set (and Rd is not R15) the V flag in the CPSR will be set if
an overflow occurs into bit 31 of the result; this may be ignored if the operands were
considered unsigned, but warns of a possible error if the operands were 2's
complement signed. The C flag will be set to the carry out of bit 31 of the ALU, the Z
flag will be set if and only if the result was zero, and the N flag will be set to the value
of bit 31 of the result (indicating a negative result if the operands are considered to be
2's complement signed).
4.5.2 Shifts
When the second operand is specified to be a shifted register, the operation of the
barrel shifter is controlled by the Shift field in the instruction. This field indicates the
type of shift to be performed (logical left or right, arithmetic right or rotate right). The
amount by which the register should be shifted may be contained in an immediate field
in the instruction, or in the bottom byte of another register (other than R15). The
encoding for the different shift types is shown in
·
Figure 4-5: ARM shift operations
.
Figure 4-5: ARM shift operations
Instruction specified shift amount
When the shift amount is specified in the instruction, it is contained in a 5 bit field which
may take any value from 0 to 31. A logical shift left (LSL) takes the contents of Rm and
moves each bit by the specified amount to a more significant position. The least
significant bits of the result are filled with zeros, and the high bits of Rm which do not
map into the result are discarded, except that the least significant discarded bit
becomes the shifter carry output which may be latched into the C bit of the CPSR when
the ALU operation is in the logical class (see above). For example, the effect of LSL #5
is shown in
·
Figure 4-6: Logical shift left
.
0
0
1
Rs
11
8
7
6
5
4
11
7 6
5
4
Shift type
00 = logical left
01 = logical right
10 = arithmetic right
11 = rotate right
Shift amount
5 bit unsigned integer
Shift type
00 = logical left
01 = logical right
10 = arithmetic right
11 = rotate right
Shift register
Shift amount specified in
bottom byte of Rs