SUB
Integer subtraction
Subtract the source from the destination and update the arithmetic flags.
Similar operations on Arm64:SUBvsubq_u8
| Form | Bits | Requires | Encoding |
|---|---|---|---|
SUB r32_dst, r32_src | 32 | x86-64 | 29 /r |
SUB r64_dst, r64_src | 64 | x86-64 | REX.W + 29 /r |
Operation#
Pseudo-C · selected form
dst = (dst - src) mod 2^width
update OF, SF, ZF, AF, CF, PFExact upstream semantics
Standard variant
let (result, carry_out, overflow, alternative_carry) := Subtract(src1, src2);
RFLAGS.OF := overflow;
RFLAGS.SF := result[operand_size-1];
RFLAGS.ZF := Bit(Is_Zero(result));
RFLAGS.AF := alternative_carry;
RFLAGS.PF := Bit(Is_Parity_Even(result[0 +: 8]));
RFLAGS.CF := carry_out;What to watch for
- This sample covers 32-bit and 64-bit register operands.
- CF reports an unsigned borrow; OF reports signed overflow.
Architectural details#
- Flags
- Updates OF, SF, ZF, AF, CF, and PF.
- Destination
- Writes the destination register.
- Encoding
REX.W + 29 /r- Operands
r64_dstread / writer64_srcread
- Coverage
- Selected 32/64-bit register forms; 64-bit execution mode. LEA uses a 64-bit address size. Other operand and encoding forms are outside this sample.
Exception information & execution requirements
#UD
No memory is accessed by this selected form. Consult the source for execution-mode and prefix exceptions.
Feature availability alone does not guarantee execution: OS state and execution-level controls also apply. Use the linked architecture documentation for the full exception conditions.
Sources & provenance#
Technical fields are imported from pinned upstream files. Explanations and explorer behavior are maintained separately.
Intel · SUB-Subtract.xml
- Revision
4ebe7f0ac1bd00f46244c49bb72c503ce368def7- SHA-256
cd86ea9a8ed1f11bd9befc2d45e6dda4af7cf0f60716d8c2e8cf635592a64c0b- Terms
- Intel SDM terms; see License.md