<<< ADC Examples | Index | SBB Instruction, Cont >>> |
After subtraction, the carry flag CF = 1 indicates a need for a borrow.
The SBB (subtract with borrow) instruction subtracts both a source operand and the value of the Carry flag CF from a destination operand:
SBB op1, op2 ; op1 -= op2, op1 -= CF
The possible operands are the same as for the ADC instruction.
The following fragment of code performs 64-bit subtraction:
mov edx, 1 ; upper half mov eax, 0 ; lower half sub eax, 1 ; subtract 1 from the lower half, set CF. sbb edx, 0 ; subtract carry CF from the upper half.
The example logic:
Sets EDX:EAX to 00000001h:00000000h.
Subtracts 1 from the value in EDX:EAX.
The lower 32 bits are subtracted first, setting the Carry flag CF.
The upper 32 bits are subtracted next, including the Carry flag.
<<< ADC Examples | Index | SBB Instruction, Cont >>> |