
Instruction Set
4-12
ADC
ADC
This example adds two 3-byte packed decimal 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 ADC.
ADC 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.
The microcontroller does not provide an instruction that performs decimal addition. To add
decimal numbers, use ADD to perform binary addition, and then convert the result to decimal
using AAA or DAA.
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.
PADDEND1
DB
00h,25h,86h,17h
; 258617 packed BCD
PADDEND2
DB
00h,04h,21h,45h
; 42145 packed BCD
; multibyte packed decimal addition: PADDEND1 = PA PADDEND2
; add right bytes
MOV
AL,PA 3
ADD
AL,PA 3
DAA
MOV
PA 3,AL
; add next bytes
MOV
AL,PA 2
ADC
AL,PA 2
DAA
MOV
PA 2,AL
; add next bytes
MOV
AL,PA 1
ADC
AL,PA 1
DAA
MOV
PA 1,AL
; if CF is 1, propagate carry into left byte
JC
ADD_CARRY
JMP
CONTINUE
ADD_CARRY:
MOV
PADDEND1,1
CONTINUE:
...
Summary of Contents for Am186 Series
Page 1: ...Am186 and Am188 Family Instruction Set Manual February 1997...
Page 10: ...Table of Contents x...
Page 18: ...Programming 1 8...
Page 40: ...Instruction Set Listing 3 14...