EasyManua.ls Logo

Intel 8080 - B4_Page_32

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
The following routine uses an
ADC
instruction to add the low-order bytes of the operands. This could cause
the
result
to
be
high
by
one
if
the carry flag were left set
by
some previous instruction. This routine avoids
the
problem
by
clearing the carry flag with the XRA instruction just before LOOP.
Label
MADD:
LOOP:
DONE:
FIRST:
SECND:
Code
LXI
LXI
XRA
LDAX
ADC
STAX
DCR
]Z
INX
INX
]MP
DB
DB
DB
DB
DB
DB
Operand
B,FIRST
H,SECND
A
B
M
B
E
DONE
B
H
LOOP
90H
OBAH
84H
8AH
OAFH
32H
Comment
;B
AND C ADDRESS
FI
RST
;H
AND L ADDRESS SECND
;CLEAR CARRY
FLAG
;LOAD
BYTE
OF FIRST
;ADD
BYTE
OF SECND
;WITH
CARRY
;STORE
RESULT
AT
FIRST
;DONE
IF
E = 0
;POINT TO
NEXT BYTE OF
;FIRST
;POINT TO
NEXT
BYTE
OF
;SECND
;ADD
NEXT
TWO
BYTES
Since none of the instructions
in
the program loop affect the carry flag except ADC, the addition with carry
will
proceed correctly.
When
location DONE
is
reached, bytes FIRST through FIRST+2
will
contain lA6AB7, which
is
the sum shown
at the beginning
of
this section arranged from low-order to high-order byte.
In
order to create a multibyte subtraction routine, it
is
necessary only to duplicate the multibyte addition routine
of this section, changing the
ADC
instruction to an
SBB
instruction. The program
will
then
,ubtract
the number
beginning at
SECND from the number beginning at FIRST, placing the re,ult at FIRST.
DECIMAL
ADDITION
6-12
Any 4-bit data quantity may
be
treated
as
a decimal number
a,
long
as
it
represents one
of
the decimal digits
from
0 through 9, and does not contain any of the bit patterns representing the hexadecimal digits A through
F.
In
order to preserve this decimal interpretation when performing addition, the value 6 must
be
added to the
4-bit quantity whenever the addition produces a
result between
10
and 15. This
is
because each 4-bit data
quantity can
hold 6 more combinations
of
bits than there are decimal digits.

Table of Contents

Related product manuals