rsb
Reverse Subtract (Thumb)
RSB <Rd>, <Rn>, #0
Reverse Subtract (Thumb 16-bit).
Details
Subtracts a register from zero and writes the result to the destination register (two's complement negation). Sets the N, Z, C, and V flags based on the result. This Thumb 16-bit instruction is available in all Thumb-capable processors.
Pseudocode Operation
result ← 0 - Rn
Rd ← result
N ← (result[31] == 1)
Z ← (result == 0)
C ← BorrowFrom(0 - Rn)
V ← OverflowFrom(0 - Rn)
Example
RSB r0, r1, #0
Encoding
Binary Layout
010000
1001
Rn
Rd
Operands
-
Rd
Destination general-purpose register -
Rn
First source / base general-purpose register
Reference (Arm AArch32 ISA)
Instruction Forms
| Encoding | Instruction | ISA | Bit pattern | ||
|---|---|---|---|---|---|
| 0x02600000 | RSB{<c>}{<q>} {<Rd>,} <Rn>, #<const> | A32 | cond | 0010 | 011 | 0 | Rn | Rd | imm12 | ||
| 0x4240 | RSB<c>{<q>} {<Rd>, }<Rn>, #0 | T32 | 010000 | 1001 | Rn | Rd | ||
| 0xF1C00000 | RSB<c>.W {<Rd>,} <Rn>, #0 | T32 | 11110 | i | 0 | 1110 | 0 | Rn | 0 | imm3 | Rd | imm8 | ||
| 0x00600060 | RSB{<c>}{<q>} {<Rd>,} <Rn>, <Rm>, RRX | A32 | cond | 0000 | 011 | 0 | Rn | Rd | 00000 | 11 | 0 | Rm | ||
| 0x00600000 | RSB{<c>}{<q>} {<Rd>,} <Rn>, <Rm> {, <shift> #<amount>} | A32 | cond | 0000 | 011 | 0 | Rn | Rd | imm5 | stype | 0 | Rm | ||
| 0xEBC00030 | RSB{<c>}{<q>} {<Rd>,} <Rn>, <Rm>, RRX | T32 | 1110101 | 1110 | 0 | Rn | 0 | 000 | Rd | 00 | 11 | Rm | ||
| 0xEBC00000 | RSB{<c>}{<q>} {<Rd>,} <Rn>, <Rm> {, <shift> #<amount>} | T32 | 1110101 | 1110 | 0 | Rn | 0 | imm3 | Rd | imm2 | stype | Rm | ||
| 0x00600010 | RSB{<c>}{<q>} {<Rd>,} <Rn>, <Rm>, <shift> <Rs> | A32 | cond | 0000 | 011 | 0 | Rn | Rd | Rs | 0 | stype | 1 | Rm |
Description
Reverse Subtract (immediate) subtracts a register value from an immediate value, and writes the result to the destination register.
If the destination register is not the PC, the RSBS variant of the instruction updates the condition flags based on the result.
The field descriptions for <Rd> identify the encodings where the PC is permitted as the destination register. ARM deprecates any use of these encodings. However, when the destination register is the PC:
Operation
if ConditionPassed() then
EncodingSpecificOperations();
(result, nzcv) = AddWithCarry(NOT(R[n]), imm32, '1');
if d == 15 then // Can only occur for A32 encoding
if setflags then
ALUExceptionReturn(result);
else
ALUWritePC(result);
else
R[d] = result;
if setflags then
PSTATE.<N,Z,C,V> = nzcv;