sbcs
Subtract with Carry and Set Flags
SBCS <Wd>, <Wn>, <Wm>
Subtracts with borrow and updates flags.
Details
Subtracts the value in Wm and the inverted Carry flag from Wn, storing the result in Wd and updating the condition flags. The Carry flag is inverted before subtraction, so if C=0 (no carry), a borrow of 1 is subtracted. All four flags (N, Z, C, V) are updated based on the result. This instruction is available in AArch64 and A32/T32 variants.
Pseudocode Operation
result ← Wn - Wm - (1 - C)
Wd ← result[31:0]
N ← result[31]
Z ← (result == 0)
C ← NOT(BorrowFrom(Wn - Wm - (1 - C)))
V ← OverflowFrom(Wn - Wm - (1 - C))
Example
SBCS w0, w1, w2
Encoding
Binary Layout
0
1
1
11010000
Rm
000000
Rn
Rd
Operands
-
Wd
Destination 32-bit integer register -
Wn
First source / base 32-bit integer register -
Wm
Second source / offset 32-bit integer register
Reference (Arm A64 ISA)
Instruction Forms
| Encoding | Instruction | ISA | Bit pattern | ||
|---|---|---|---|---|---|
| 0x7A000000 | SBCS <Wd>, <Wn>, <Wm> | A64 | 0 | 1 | 1 | 11010000 | Rm | 000000 | Rn | Rd | ||
| 0xFA000000 | SBCS <Xd>, <Xn>, <Xm> | A64 | 1 | 1 | 1 | 11010000 | Rm | 000000 | Rn | Rd |
Description
Subtract with Carry, setting flags, subtracts a register value and the value of NOT (Carry flag) 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 = X[n, datasize]; bits(datasize) operand2 = X[m, datasize]; bits(4) nzcv; operand2 = NOT(operand2); (result, nzcv) = AddWithCarry(operand1, operand2, PSTATE.C); PSTATE.<N,Z,C,V> = nzcv; X[d, datasize] = result;