Łukasz Przeniosło
Łukasz Przeniosło

Reputation: 2949

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.

Upvotes: 6

Views: 13035

Answers (2)

Laurent H.
Laurent H.

Reputation: 6526

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

Upvotes: 12

fuz
fuz

Reputation: 93117

The instruction RSB r1, r2, r3, LSL #1 shifts the contents of r3 left by one place, subtracts r2 and stores the result in r1 without setting flags. In pseudocode, it does this:

r1 = r3 + r3 - r2

Note that the third operand is a flexible operand comprising r3, LSL #1. See this page for more details.

Upvotes: 3

Related Questions