EMAC PRIMER Instruction Manual page 60

Table of Contents

Advertisement

LESSON 19: Using the XTHL Instruction.
NEW INSTRUCTIONS
XTHL
Exchange L with the value at memory address SP and exchange H with the value at memory address SP
+ 1. No flags are affected.
PUSH H
Put the HL register pair on the stack. No flags are affected.
POP
H
Get the HL register pair from the stack. No flags are affected.
MOV
A,M
Copy the byte from the memory location specified by the HL register pair to the A register. No flags are
affected.
MOV
M,A
Copy the byte from the A register to the memory location specified by the HL register pair. No flags are
affected.
DCR
D
Decrement the D register. Z,S,P and AC flags are affected.
One of the best uses for the XTHL instruction is in programs where there is a need for more registers. You can load the HL
register with a value and push it on the stack (call this value HL2) and then load HL with a another value (call this value
HL1). After that, an XTHL instruction will save HL1 on the stack and then load HL with HL2 allowing HL2 to be accessed.
If another XTHL instruction is executed the stack will hold HL2 again and HL will equal HL1 which will allow HL1 to be
accessed.
The program below demonstrates this action by multiplying DE by HL using repeating additions and returning the
result with the BC register pair being the most significant word and HL being the least significant word.
org
push
lxi
mov
mov
loop:
dad
jnc
inx
nocarry:
xthl
dcx
mov
ora
xthl
jnz
pop
rst
ADDRESS
FF01
FF02
FF03
FF04
FF05
FF06
FF07
FF08
FF09
FF0A
FF0B
FF0C
continued on next page...
op code = E3
op code = C5
op code = C1
op code = 7E
op code = 77
op code = 15
0ff01h
; starting address of program
h
; put HL on stack.
; the number of adds left to go.
h,0000
; HL=0000
b,h
; B=0
c,l
; C=0 (BC=0)
d
; HL= HL + DE
nocarry
; skip INX B if carry flag = 0
b
; if result too big for HL
; add 1 to BC
; swap sum with number of adds to go
h
; 1 less add left to go
a,h
; A=H
l
; if H and A = 0 then zero flag = 1
; swap new # left to go, with sum
loop
; if zero flag = 0, do another DAD D
; At this point, adds left to go is 0.
psw
; clear the stack and quit
7
; end of program
DATA
INSTRUCTION
E5
PUSH H
21
LXI
H,0000
00
00
44
MOV
B,H
4D
MOV
C,L
19
DAD
D
D2
JNC
FF0C
0C
FF
03
INX
B
E3
XTHL
This value is
60

Advertisement

Table of Contents
loading

Table of Contents