EMAC PRIMER Instruction Manual page 38

Table of Contents

Advertisement

LESSON 9: Binary Coded Decimal Sixteen-Bit Addition
NEW INSTRUCTION
DAA
Change the value in the A register to two binary coded decimal digits. This is done by: (a) Adding 6 to the
A register if the value of its lower 4 bits is greater than 9, or if the auxiliary carry flag is set. (b) Adding 6 to
the upper 4 bits of the A register if they are greater than 9 or if the carry flag is set. The Z,S,P,CY, and AC
flags are affected.
NOP
This instruction does nothing but take up one byte in a program. No flags are affected.
Decimal numbers can be stored in binary form as binary coded decimal (BCD) numbers. Each decimal digit takes 4 bits
just as hex numbers do, but in BCD, digits A-F are not valid numbers.
For example, the hex number 9999 is 9999 in BCD. The DAA instruction was provided so it would be possible to perform
binary coded decimal math using the ordinary hex addition instructions.
According to its definition, DAA will give the following results following a hex addition instruction:
19
+29(hex add)
32
+06(DAA)
48
Note that DAA can only give 2 decimal digits and the carry flag as a result. In these examples the carry flag represents the
hundreds digit.
The following program will add the BCD number in DE to the BCD number in BC and store the BCD result in BC.
org
mov
add
daa
mov
mov
adc
daa
mov
rst
end
ADDRESS
FF01
FF02
FF03
FF04
FF05
FF06
FF07
FF08
FF09
Enter the program into memory then press reset and load BC with 1934 and load DE with 1879.
CURRENT PC
FF01
Single step to FF03 and examine the A register (it will be AD hex). Since both the upper 4 and lower 4
binary digits of the A register are greater than 9 then 66 will be added to it in the DAA instruction that
follows.
op code = 27
op code = 00
67
+75(hex add)
DC
+66(DAA)
142
0ff01
; add low order bytes 1st
a,c
; A is a copy of C
e
; A = A + E. Set carry flag if A<E
; decimal adjust accumulator
c,a
; C = A + E
; add high order bytes and carry from DAA
a,b
; A is a copy of B
d
; A = A + D + carry flag
; decimal adjust accumulator
b,a
; B = A
7
; stop the program
DATA
INSTRUCTION
79
MOV
A,C
83
ADD
E
27
DAA
4F
MOV
C,A
78
MOV
A,B
8A
ADC
D
27
DAA
47
MOV
B,A
FF
RST
7
38
43
+72(hex add)
B5
+60(DAA)
115

Advertisement

Table of Contents
loading

Table of Contents