Instruction Set
4-241
SUB
SUB
Flag Settings After Instruction
Examples
This example subtracts one 16-bit unsigned number in memory (the subtrahend) from
another 16-bit unsigned number in a register (the minuend).
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.)
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
Processor Status
Flags Register
reserved
OF DF
IF TF SF ZF
AF
PF
CF
? = undefined; – = unchanged
OF=1 if result larger than destination operand
OF=0 otherwise
AF=1 if carry or borrow to low nibble
AF=0 otherwise
PF=1 if low byte of result has even number of set bits
PF=0 otherwise
CF=1 for carry or borrow to high-order bit
CF=0 otherwise
–
–
–
res
res
res
SF=1 if result is 0 or positive
SF=0 if result is negative
ZF=1 if result equal to 0
ZF=0 if result not equal to 0
UMINUEND
DW
364
; 016Ch
USUBTRAHEND
DW
25
; 0019h
; 16-bit unsigned subtraction: AX = AX - USUBTRAHEND
MOV
AX,UMINUEND
; AX = 016Ch = 364
SUB
AX,USUBTRAHEND
; AX = 0153h = 339
SMINUEND
DD
44761089
; 02AB0001h
SSUBTRAHEND
DD
-990838848
; C4F0FFC0h
; 32-bit integer subtraction: SMINUEND = SMINUEND - SSUBTRAHEND
; low word subtraction
MOV
AX,WORD PTR SSUBTRAHEND
; copy subtrahend
SUB
WORD PTR SMINUEND,AX
; subtract
; high word subtraction
MOV
AX,WORD PTR SSUBT 2
; copy subtrahend
SBB
WORD PTR SM 2,AX
; subtract with borrow
; SMINUEND = C79BFFC1h
; = -946077759
Содержание Am186 Series
Страница 1: ...Am186 and Am188 Family Instruction Set Manual February 1997...
Страница 10: ...Table of Contents x...
Страница 18: ...Programming 1 8...
Страница 40: ...Instruction Set Listing 3 14...