Chapter
6.
Programming
Techniques
Decimal addition
is
performed
by
letting each 8-bit byte represent two 4-bit decimal digits. The bytes are
summed
in
the accumulator
in
standard fashion, and the
DAA
(decimal adjust accumulator) instruction
is
then
used to convert the 8-bit binary
result to the correct representation
of
2 decimal digits. For multibyte strings,
you must perform the
decimal adjust before adding the next higher·order bytes. This
is
because you need the
carry
flag
setting from the
DAA
instruction for adding the higher·order bytes.
To perform the
decimal addition:
the process works
as
follows:
2985
+4936
7921
1.
Clear the Carry and add the two lowest-order digits
of
each number (remember that each 2
decimal digits are represented by .one byte).
carry
85
= 10000101 B
36
= 00110110B
o
~Q]10111011B
Carry = 0 , Auxiliary Carry = 0
The accumulator now contains
OBBH.
2. Perform a
DAA
operation. Since the rightmost four bits are greater than 9, a 6
is
added to the
accumulator.
Accumulator
= 10111011 B
6
= 0110B
11000001
B
Since the
leftmost bits are greater than 9, a 6
is
added to these bits, thus
~etting
the carry flag.
Accumulator = 11000001 B
6
= 0110 B
Carry
flag
==
1
/]00100001B
The accumulator now contains
21
H.
Store these two digits.
6-13