EMAC PRIMER Instruction Manual page 35

Table of Contents

Advertisement

LESSON 7: Sixteen-Bit Addition
NEW INSTRUCTIONS
ADD E op code = 83
Adds the E register to the A register, storing the result in the A register. The Z,S,P,CY and AC flags are
affected.
ADC D op code = 8A
Adds the D register and the carry flag to the A register, storing the result in the A register. The Z,S,P,CY
and AC flags are affected.
The same concept used in the previous lesson can be applied to make a 16 bit addition program.
org
mov
add
mov
mov
adc
mov
rst
end
ADDRESS
FF01
FF02
FF03
FF04
FF05
FF06
FF07
If the previous program is still in memory the only changes that need to be made are that the SUB instruction must be
replaced with an ADD, and the SBC with an ADC. This is done by changing the byte at address FF02 to 83 and the byte at
address FF05 to 8A. If the program is no longer in memory, load the one listed above.
Load the BC register pair with 2302 hex and load the DE register pair with 10FF hex. The following is an equation that the
program will perform.
If you single step the program starting at address FF01 you will see the following after each step:
CURRENT PC
FF01
A equals C which is 02.
FF02
A = A + E. Since A + E = 101 hex and that is too big to fit in the A register, the carry flag is set (examine
bit 0 of the flag register) and the A register is 01.
FF03
C equals A which is 01.
FF04
A equals B which is 23 hex.
FF05
The D register and the carry flag are added to the A register (A = A + D + carry flag = 23 hex + 10 hex + 1
= 34 hex).
FF06
B equals A which is 34 hex
0ff01
; add low order bytes 1st
a,c
; A is a copy of C
e
; A = A + E. Set carry if result > 0FFh
c,a
; C = A + E
; add high order bytes and carry flag
a,b
; A is a copy of B
d
; A = A + D + carry flag
b,a
; B = A
7
; stop the program
DATA
INSTRUCTION
79
MOV
A,C
83
ADD
E
4F
MOV
C,A
78
MOV
A,B
8A
ADC
D
47
MOV
B,A
FF
RST
7
2302 hex
+10FF hex
=3401 hex
35

Advertisement

Table of Contents
loading

Table of Contents