Barrel Shifter Flashcards
Barrel Shifter
The barrel shifter is a functional unit which can be used in a number of different circumstances. It provides five types of shifts and rotates which can be applied to Operand2. (These are not operations themselves in ARM mode.)
LSL
– Logical Shift Left
Example: Logical Shift Left by 4.
Equivalent to << in C.
LSR
– Logical Shift Right
Example: Logical Shift Right by 4.
Equivalent to >> in C. i.e. unsigned division by a power of 2.
ASR
– Arithmetic Shift Right
Example: Arithmetic Shift Right by 4, positive value.
ASR
– Arithmetic Shift Right
Example: Arithmetic Shift Right by 4, negative value.
Equivalent to >> in C. i.e. signed division by a power of 2.
ROR
– Rotate Right
Example: Rotate Right by 4.
Bit rotate with wrap-around.
RRX
– Rotate Right Extended
Example: Rotate Right Extended.
33-bit rotate with wrap-around through carry bit.
MOV r0, r0, LSL #1
Multiply R0 by two.
MOV r1, r1, LSR #2
Divide R1 by four (unsigned).
MOV r2, r2, ASR #2
Divide R2 by four (signed).
MOV r3, r3, ROR #16
Swap the top and bottom halves of R3.
ADD r4, r4, r4, LSL #4
Multiply R4 by 17. (N = N + N * 16)
RSB r5, r5, r5, LSL #5
Multiply R5 by 31. (N = N * 32 – N)
Certain C operations don’t map onto available CPU operations. \_\_\_
and\_\_\_
are two of those operations.
At the start I mentioned that certain C operations don’t map onto available CPU operations. ROR
andRRX
are two of those operations.