
Instruction Set
4-15
ADD
ADD
Flag Settings After Instruc tion
Examples
This example adds two 16-bit integers.
This example adds two 32-bit unsigned numbers.
T ips
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
SADDEND2
DW
DW
-6360
723
; E6ECh
; 02D3h
; add signed numbers
MOV
ADD
AX,SADDEND2
SADDEND1,AX
; AX = 723
; SADDEND1 = -5637
UADDEND1
UADDEND2
DD
DD
592535620
3352720
; 23516044h
; 00332890h
; 32-bit unsigned addition: UADDEND1 = UADDEND1 + UADDEND2
; add left words (bytes and words reversed in memory)
MOV
AX,WORD PTR UADDEND2
ADD
WORD PTR UADDEND1,AX
; AX=2890h
; UADEND1=2351h::(2890h+6044h)
=235188D4h
; add right words
MOV
AX,WORD PTR UADDEND2+2
ADC
WORD PTR UADDEND1+2,AX
; AX=0033h
; UADDEND1=(2351h+0033h)::88D4h
; =238488D4h
; =595888340