Instruction Set
4-15
ADD
ADD
Flag Settings After Instruction
Examples
This example adds two 16-bit integers.
This example adds two 32-bit unsigned numbers.
Tips
To add two integers or two unsigned numbers that are both stored in memory, copy one
of them to a register before using ADD.
ADD requires both operands to be the same size. Before adding an 8-bit integer to 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 add numbers larger than 16 bits, use ADD to add the low words, and then use ADC to
add each of the subsequently higher words.
Use INC instead of ADD within a loop when you want to increase a value by 1 each time
the loop is executed.
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
SADDEND1
DW
-6360
; E6ECh
SADDEND2
DW
723
; 02D3h
; add signed numbers
MOV
AX,SADDEND2
; AX = 723
ADD
SADDEND1,AX
; SADDEND1 = -5637
UADDEND1
DD
592535620
; 23516044h
UADDEND2
DD
3352720
; 00332890h
; 32-bit unsigned addition: UADDEND1 = UA UADDEND2
; add left words (bytes and words reversed in memory)
MOV
AX,WORD PTR UADDEND2
; AX=2890h
ADD
WORD PTR UADDEND1,AX
; UADEND1=2351h::(2890h+6044h)
=235188D4h
; add right words
MOV
AX,WORD PTR U2
; AX=0033h
ADC
WORD PTR U2,AX
; UADDEND1=(2351h+0033h)::88D4h
; =238488D4h
; =595888340
Содержание 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...