On Day 8 we kept saying "Operand2 can be a shifted register." Today we unlock that. The barrel shifter lets ARM shift or rotate an operand for free, inside the same instruction — a trick that gives RISC ARM surprising muscle.
On most CPUs, shifting a value and then using it takes two instructions. ARM puts a barrel shifter right before the ALU, so it can shift Operand2 on the way in — no extra instruction, no extra cycle:
That single line computes r0 = r1 + r2×4. The shift happened for free as part of the add. This is the feature that makes ARM assembly feel unusually expressive.
It's like a coffee machine that grinds the beans as it brews — you don't grind first in a separate step. The shifter "grinds" the operand on its way into the ALU.
| Type | Name | What it does |
|---|---|---|
| LSL | Logical Shift Left | shift left, fill with 0 → multiply by 2ⁿ |
| LSR | Logical Shift Right | shift right, fill with 0 → unsigned ÷ 2ⁿ |
| ASR | Arithmetic Shift Right | shift right, copy the sign bit → signed ÷ 2ⁿ |
| ROR | Rotate Right | bits that fall off the right wrap to the left |
| RRX | Rotate Right eXtended | rotate right by 1 through the carry flag |
The key subtlety: right-shifting a signed number must preserve its sign. LSR fills with zeros (wrong for negatives); ASR copies the sign bit (correct):
So: LSR for unsigned, ASR for signed division by powers of two.
Since x << n = x × 2ⁿ, you can build many multiplications from shifts and adds — often in a single instruction:
Compilers love this: multiplying by small constants becomes one or two fast shift-add instructions instead of a slower multiply. (For variable multiplies there's a real MUL — Day 13.)
If you only want to shift (no add), use MOV with a shifted operand — there's no separate "SHL" instruction in classic ARM:
The shift amount can also be a register (LSL r3) for a variable shift. And with the S suffix, the bit shifted out lands in the carry flag — handy for serial bit work.
ARM bolts a barrel shifter onto Operand2, so a shift/rotate rides along with almost any data-processing instruction for free. Shift-left = multiply, shift-right = divide (LSR unsigned, ASR signed), and shift+add builds constant multiplies in one instruction.
r1 + (r1<<2)).MOV Rd, Rn, LSL #n — no dedicated shift instruction.r0 = r1 × 16.r0 = r1 × 3 in one instruction?Hardware that shifts/rotates an instruction's second operand before the ALU uses it — for free, in the same cycle and instruction.
LSL = shift left (×2ⁿ). LSR = shift right filling zeros (unsigned ÷). ASR = shift right copying the sign bit (signed ÷).
Shift-and-add: ×5 is ADD r0, r1, r1, LSL #2; ×7 is RSB r0, r1, r1, LSL #3.