EMAC PRIMER Instruction Manual page 32

Table of Contents

Advertisement

LESSON 5: Eight-Bit Subtraction
NEW INSTRUCTION
SUB
C
The C register is subtracted from the A register with the result being stored in the A register. The Z,S,P,CY
and AC flags are affected.
If the previous program is still in memory and you change the instruction at FF02 to 91 (SUB C) the following program is the
result. This program will subtract the C register from the B register and store the result in the accumulator. This is done by
copying the value of B into A and then subtracting C from A. The result will be in the A register.
org
loop:
mov
sub
rst
end
ADDRESS
FF01
FF02
FF03
1)
To test the SUB C instruction, load the program into memory and move the program counter to FF01. Load the
BC register pair with 0906, which is the same as loading B with 9 and C with 6, then run the program. When the
program stops at FF03, you will notice that the A register is now 3 and if you convert the flag register to binary you
will see that the carry flag is 0.
2)
Press the reset button, load B with 1F and C with 3D then run the program. You will see that the A register is E2
and the carry flag is 1. In every subtraction the carry flag is set if the number in the A register is smaller than the
value being subtracted from it (in this case the A register was 1F and 3D was subtracted from it). The carry flag
could more appropriately be referred to as a "borrow flag" when the flag value is the result of a subtraction.
op code = 91
0ff01
a,b
; A is a copy of B
c
; subtract C from A
7
; return control to MOS
DATA
INSTRUCTION
78
MOV
91
SUB
FF
RST
A,B
C
7
32

Advertisement

Table of Contents
loading

Table of Contents