EMAC PRIMER Instruction Manual page 49

Table of Contents

Advertisement

LESSON 15: Using Register Indirect Addressing to Perform 24-Bit Addition
NEW INSTRUCTIONS
ADD
M
Adds the byte in memory pointed to by the HL register pair to the A register, storing the result in the A
register. The Z,S,P,CY and AC flags are affected.
ADC
M
Adds the carry flag and the byte in memory pointed to by the HL register pair to the A register, storing the
result in the A register. The Z,S,P,CY and AC flags are affected.
INX
H
Increment the HL register pair. No flags are affected.
Sometimes the need arises to add two 24 bit numbers. This can be done using register indirect addressing, as in the
example program below. The program adds the 3 byte number at addresses FF10, FF11 and FF12 to the 3 byte number in
the C,D and E registers and stores the result in C,D and E. The byte in E and the byte at FF10 are the least significant
bytes and the byte in C and the byte at FF12 are the most significant bytes.
org
lxi
mov
add
mov
inx
mov
adc
mov
inx
mov
adc
mov
rst
num:
db
end
ADDRESS
FF01
FF02
FF03
FF04
FF05
FF06
FF07
FF08
FF09
FF0A
FF0B
FF0C
FF0D
FF0E
FF0F
FF10
FF11
FF12
Load the the above program and data into memory. After loading the program, the 3 byte number stored in memory
addresses FF12, FF11 and FF10 will be 0EA35C. Press the reset button then load C with 01 and DE with F7BF so that C
and DE will contain the 3 byte number 01F7BF, and do the following:
CURRENT PC
FF01
Single step and HL will be loaded with FF10 which is the address of least significant digit of the three byte
number that is stored in memory.
op code = 86
op code = 8E
op code = 23
0ff01h
h,num
a,e
m
e,a
h
a,d
m
d,a
h
a,c
m
c,a
7
5Ch,0A3h,0Eh
DATA
INSTRUCTION
21
LXI
H,FF10
10
FF
7B
MOV
A,E
86
ADD
M
5F
MOV
E,A
23
INX
H
7A
MOV
A,D
8E
ADC
M
57
MOV
D,A
23
INX
H
79
MOV
A,C
8E
ADC
M
4F
MOV
C,A
FF
RST
7
5C
(least significant byte)
A3
(2nd most significant byte)
0E
(most significant byte)
; A=least significant byte
; add data at hl address to A
; save result in E
; point to next memory address
; A=2nd most significant byte
; add carry and data at hl address to A
; save result in D
; point to next memory address
; A=most significant byte
; add carry and data at hl address to A
; save result in C
; return to MOS
; 3 bytes of storage
49

Advertisement

Table of Contents
loading

Table of Contents