
Instruction Set
4-218
S BB
S BB
This example subtracts one 32-bit integer in a register (the subtrahend) from another 32-
bit integer in memory (the minuend). This is accomplished by subtracting one word at a
time. The first subtraction uses SUB, and the subsequent subtraction uses SBB in case a
borrow was generated by the previous subtraction. (CF doubles as the borrow flag. If CF
is set, the previous subtraction generated a borrow. Otherwise, the previous subtraction
did not generate a borrow.)
T ips
To subtract an integer or an unsigned number located in memory from another number of
the same type that is also located in memory, copy one of them to a register before using
SBB.
SBB requires both operands to be the same size. Before subtracting an 8-bit integer from
a 16-bit integer, convert the 8-bit integer to its 16-bit equivalent using CBW. To convert an
8-bit unsigned number to its 16-bit equivalent, use MOV to copy 0 to AH.
To subtract numbers larger than 16 bits, use SUB to subtract the low words, and then use
SBB to subtract each of the subsequently higher words.
The processor does not provide an instruction that performs decimal subtraction. To
subtract decimal numbers, use SBB or SUB to perform binary subtraction, and then convert
the result to decimal using AAS or DAS.
ADC, ADD, SBB, and SUB set AF when the result needs to be converted for decimal
arithmetic. AAA, AAS, DAA, and DAS use AF to determine whether an adjustment is
needed. This is the only use for AF.
Related Instruc tions
If you want to
Convert an integer to its 16-bit equivalent
Convert an 8-bit unsigned binary difference to its packed decimal equivalent
Change the sign of an integer
Subtract a number from another number
See
CBW
DAS
NEG
SUB
SMINUEND
SSUBTRAHEND
DD
DD
44761089
-990838848
; 02AB0001h
; C4F0FFC0h
; 32-bit integer subtraction: SMINUEND = SMINUEND - SSUBTRAHEND
; low word subtraction
MOV
AX,WORD PTR SSUBTRAHEND
SUB
WORD PTR SMINUEND,AX
; copy subtrahend
; subtract
; high word subtraction
MOV
AX,WORD PTR SSUBTRAHEND + 2
SBB
WORD PTR SMINUEND + 2,AX
; copy subtrahend
; subtract with borrow
; SMINUEND = C79BFFC1h
; = -946077759