EMAC PRIMER Instruction Manual page 41

Table of Contents

Advertisement

Load the above program into memory then load the DE register pair with 0080 hex (128 decimal) and run the program.
This value is chosen because it will show that after you run the program, bit 7 of E is shifted into bit 0 of D, giving a result of
0100 (128 * 2 = 256 decimal). Examine the DE register pair to verify this. Run the program using other values for DE and
verify that the program really does multiply DE by 2, but make sure values are less than 8000 hex or the result won't fit in
the DE register pair.
If you want to multiply the HL register pair by 2 the DAD H instruction can be used. It adds HL to HL which is the
same as multiplying HL by 2. Below is a simple program which illustrates the DAD H instruction.
org 0ff01h
loop:
dad
jmp
ADDRESS
FF01
FF02
FF03
FF04
Load the program into memory and press reset then perform the same tests that were done for the previous example by
loading the HL register pair with the same values that DE was loaded with and single stepping. The results will be the
same.
A quick "times 10" algorithm can be made using a combination of multiply by 2 instructions and an addition instruction.
Below is the equation " X = Y * 10 " which is broken down into a form which the 8085 can easily handle:
The last equation above is translated into the following program.
org
mov
mov
dad
dad
dad
dad
rst
end
ADDRESS
FF01
FF02
FF03
FF04
FF05
FF06
FF07
Load the program into memory then load HL with 0003. After running the program, HL will be 001E which is 30 decimal.
Change the program counter back to FF01 (don't press reset, or the registers will be cleared) then run the program again.
This time HL will be 012C which is 300 decimal.
In the lesson "Using Monitor Operating System Subroutines" is a description of a service which multiplies two 16 bit
numbers.
h
; add hl to hl
loop
; do it again
DATA
INSTRUCTION
29
DAD
H
C3
JMP
FF01
01
FF
X = Y * 10
X = (Y * 5) * 2
X = ((Y * 4) + Y) * 2
X = ((Y * 2 * 2) + Y) * 2
0ff01h
d,h
; put original value of
e,l
;
HL into DE
h
; HL = HL * 2
h
; HL = HL * 2
d
; HL = HL + DE
h
; HL = HL * 2
7
; return to MOS
DATA
INSTRUCTION
54
MOV
5D
MOV
29
DAD
29
DAD
19
DAD
29
DAD
FF
RST
D,H
E,L
H
H
D
H
7
41

Advertisement

Table of Contents
loading

Table of Contents