Revision as of 06:49, 22 December 2011
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.
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.
RSB<suffix> <dest>, <op 1>, <op 2>
dest = op_2 - op_1
RSB R0, R1, R1, LSL #4 ; R0 = (R1 << 2) - R1 ; or in other words: R0 = (R1 * 15)
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|