assemblyarmbit-shiftinstructions

What does this RSB instruction do with an extra LSL #1 operand?


I am trying to figure out what this ARM assembly line does:

RSB r1, r2, r3, LSL #1

I am referring to RSB description from Keil help page but this example does not quite fit as it has more operands than the documentation.


Solution

  • The RSB instruction is a Reverse SuBtract without carry.
    The documentation indicates the syntax:

    RSB{S}{cond} {Rd}, Rn, Operand2
    

    The following usage can then be explained:

    RSB r1, r2, r3, LSL #1  
    
    1. r3, LSL #1 is Operand2 → r3 register logical left-shifted by 1 bit
    2. r2 is Rn
    3. r1 is Rd

    So the operation uses r1, r2 and r3 registers as follows: r1 = (r3 << 1) - r2