RSB
Instruction | RSB[S] |
---|---|
Function | Subtraction |
Category | Data processing |
ARM family | All |
Notes | - |
Contents |
RSB[S] : Reverse Subtract
RSB will subtract one value from another. The difference between this and SUB is that operand 2 is now the value being subtracted from. This is explained more below.
Operand 1 is a register, operand 2 can be a register, shifted register, or an immediate value (which may be shifted).
If the S bit is set (RSBS), the N and Z flags are set according to the result, and the C and V flags are set as follows: C if the result generated a borrow (a not carry; unsigned underflow); V if the result generated a signed overflow.
Because operand 2 is able to be a register or immediate with shifting, you can do things such as negation (0 - Op1) or various types of fast multiplication.
There is also RSC to perform subtraction with the Carry flag considered.
Syntax
RSB<suffix> <dest>, <op 1>, <op 2>
Function
dest = op_2 - op_1
Example
RSB R0, R1, R1, LSL #4 ; R0 = (R1 << 2) - R1 ; or in other words: R0 = (R1 * 15)
Technical
The instruction bit pattern is as follows:
31 - 28 | 27 | 26 | 25 | 24 - 21 | 20 | 19 - 16 | 15 - 12 | 11 - 0 |
---|---|---|---|---|---|---|---|---|
condition | 0 | 0 | I | 0 0 1 1 | S | op_1 | dest | op_2/shift |