EasyManua.ls Logo

Intel 8080 - B4_Page_34

Intel 8080
224 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Chapter
6.
Programming
Techniques
3.
Add the next group of two digits:
carry
29 =
00101001 B
49 =
01001001 B
g]01110011B
Carry = 0
~
'AUXiliary
Carry = 1
The accumulator now contains 73H.
4.
Perform a
DAA
operation. Since the auxiliary carry flag
is
set, 6
is
added to the accumulator.
Accumulator =
01110011B
6=
0110B
Carry flag
= 0
/m01111001B
Since the leftmost 4 bits are
less
than 10 and the carry flag
is
reset,
no
further action occurs.
Thus, the correct
decimal result 7921
is
generdted
in
two bytes.
A routine which adds decimal numbers, then,
is
exactly analogous to the multibyte addition routine
MADD
of
the last section, and may
be
produced
by
inserting the instruction
DAA
after the
ADC
M instruction
of
that
example.
Each iteration of the program loop
will
add two decimal digits {one byte)
of
the numbers.
DECIMAL SUBTRACTION
6-14
()(~cimal
subtraction
is
considerably more complicated than decimal addition.
In
general, the process consists
of
generating the tens complement
of
the subtrahend digit, and then adding the result
to
the minuend digit. For
example, to subtract 34 from 56, form the tens complement
of
34 (99-34=65+ 1 =66). Then, 56+66= 122.
By
truncating off the carry
out
of the high order digit,
we
get 22, the correct result.
The problem of handling borrows arises
in
multibyte decimal subtractions. When
no
borrow occurs from a sub-
tract, you want to
use
the tens complement
of
the subtrahend for the next operation.
If
a borrow does occur,
you want
to
use
the nines complement
of
the subtrahend.
Notice
that
the meaning
of
the carry
flag
is
inverted because you are dealing with complemented data. Thus, a
one bit
in
the carry flag indicates
no
borrow; a zero bit
in
the carry
flag
indicates a borrow. This inverted carry
flag setting can be
used
in
an add operation to form either the nines or tens complement
of
the subtrahend.

Table of Contents

Related product manuals