Search code examples
armarmv7

ARM-V7-A ADD instruction combined with LSL


add r1, r1, r0, lsl #3

I am not sure about the operation executed with this instruction. Does it mean:

  1. Add r0 and r1, take the result and execute a left shift of 3 bits, then save the result in r1 or
  2. Add r1 and (r0 left shifted of 3 bits) then save the result in r1

Thanks in advance.


Solution

  • Most of the arithmetic and logical instructions in the Thumb and Thumb-2 instruction sets take three arguments. The first is the destination register, the second is the first operand (also a register), and the third is the flexible second operand. (If the destination register is omitted, the first operand is used as the destination.)

    In almost all cases, the flexible second operand can be:

    • A register
    • A register with a shift or rotate applied, where the available shifts are
      • ASR #n (arithmetic shift right)
      • LSL #n (logical shift left)
      • LSR #n (logical shift right)
      • ROR #n (rotate right)
      • RRX (rotate right one bit through carry)
    • A constant in the format #constant, where #constant can be:
      • Any constant that can be produced by shifting an 8-bit value left by any number of bits within a 32-bit word
      • Any constant of the form 0x00XY00XY
      • Any constant of the form 0xXY00XY00
      • Any constant of the form 0xXYXYXYXY

    So in your case, r0, lsl #3 is the second operand to the add instruction, and so the shift is performed before the add.

    For more information see the ARM developer documentation.