EMAC PRIMER Instruction Manual page 33

Table of Contents

Advertisement

LESSON 6: Sixteen-Bit Subtraction
NEW INSTRUCTIONS
SUB
E
The E 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.
SBB
D
Subtracts the D register and the carry flag from the A register with the result being stored in the A register.
The Z,S,P,CY and AC flags are affected.
MOV
A,C
The contents of the C register are copied to register A. No flags are affected.
MOV
C,A
The contents of the A register are copied to register C. No flags are affected.
MOV
B,A
The contents of the A register are copied to register B. No flags are affected.
Using the carry flag with subtraction instructions allows you to subtract 16 bit, 24 bit or even larger numbers. The following
program subtracts the value of the DE register pair from the value of the BC register pair, leaving the result in the latter.
org
mov
sub
mov
mov
sbb
mov
rst
end
ADDRESS
FF01
FF02
FF03
FF04
FF05
FF06
FF07
Load the BC register pair with 2100 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 00.
FF02
A = A - E. Since A (00) is less than E (FF), the carry flag is set (examine bit 0 of the flag register). The
subtraction will be performed as if there was a 1 digit to the left of the A register. In this case the
subtraction will be performed as if A = 100 hex. (100 hex - FF hex) = 01 so A equals 01.
FF03
C equals A which is 01.
FF04
A equals B which is 21 hex.
op code = 93
op code = 9A
op code = 79
op code = 4F
op code = 47
0ff01
; subtract low order bytes 1st
a,c
; A is a copy of C
e
; A = A - E. Set carry flag if A < E
c,a
; C = A - E
; subtract 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
93
SUB
E
4F
MOV
C,A
78
MOV
A,B
9A
SBB
D
47
MOV
B,A
FF
RST
7
2100 hex
-10FF hex
=1001 hex
33

Advertisement

Table of Contents
loading

Table of Contents