subs
Subtract and Set Flags (Immediate)
SUBS <Wd>, <Wn|Wsp>, #<imm> {, lsl #<shift>}
Subtracts immediate and updates flags.
Details
Subtracts a 12-bit immediate value (optionally shifted left by 0 or 12 bits) from the source register and updates all condition flags. The N, Z, C, and V flags are set according to the result. This instruction executes in AArch64 state and requires no special privileges.
Pseudocode Operation
imm_val ← (imm12 << (sh * 12)); result ← Wn - imm_val; Wd ← result; N ← result[31]; Z ← (result == 0); C ← BorrowFrom(Wn, imm_val); V ← OverflowFrom(Wn, imm_val, result)
Example
SUBS w0, Wn, #16
Encoding
Binary Layout
0
1
1
100010
sh
imm12
Rn
Rd
Operands
-
Wd
Destination 32-bit integer register -
Wn
First source / base 32-bit integer register -
imm
Imm
Reference (Arm A64 ISA)
Instruction Forms
| Encoding | Instruction | ISA | Bit pattern | ||
|---|---|---|---|---|---|
| 0x6B200000 | SUBS <Wd>, <Wn|WSP>, <Wm>{, <extend> {#<amount>}} | A64 | 0 | 1 | 1 | 01011 | 00 | 1 | Rm | option | imm3 | Rn | Rd | ||
| 0xEB200000 | SUBS <Xd>, <Xn|SP>, <R><m>{, <extend> {#<amount>}} | A64 | 1 | 1 | 1 | 01011 | 00 | 1 | Rm | option | imm3 | Rn | Rd | ||
| 0x71000000 | SUBS <Wd>, <Wn|WSP>, #<imm>{, <shift>} | A64 | 0 | 1 | 1 | 100010 | sh | imm12 | Rn | Rd | ||
| 0xF1000000 | SUBS <Xd>, <Xn|SP>, #<imm>{, <shift>} | A64 | 1 | 1 | 1 | 100010 | sh | imm12 | Rn | Rd | ||
| 0x6B000000 | SUBS <Wd>, <Wn>, <Wm>{, <shift> #<amount>} | A64 | 0 | 1 | 1 | 01011 | shift | 0 | Rm | imm6 | Rn | Rd | ||
| 0xEB000000 | SUBS <Xd>, <Xn>, <Xm>{, <shift> #<amount>} | A64 | 1 | 1 | 1 | 01011 | shift | 0 | Rm | imm6 | Rn | Rd |
Description
Subtract (immediate), setting flags, subtracts an optionally-shifted immediate value from a register value, and writes the result to the destination register. It updates the condition flags based on the result.
Operation
bits(datasize) result; bits(datasize) operand1 = if n == 31 then SP[]<datasize-1:0> else X[n, datasize]; bits(datasize) operand2; bits(4) nzcv; operand2 = NOT(imm); (result, nzcv) = AddWithCarry(operand1, operand2, '1'); PSTATE.<N,Z,C,V> = nzcv; X[d, datasize] = result;