EMAC PRIMER Instruction Manual page 63

Table of Contents

Advertisement

LESSON 20: Subroutines
NEW INSTRUCTIONS
CALL <addr> op code = C3
Put the address of the next instruction on the stack and load the program counter with the two bytes that
follow the op code. The byte immediately following the op code is the least significant byte of the address
and the one after that is the most significant byte.
RET
Remove a 16 bit address from the stack and load it into the program counter. No flags are affected.
DCR
H
Decrement the H register. Z,S,P and AC flags are affected.
PUSH B
Put the BC register pair on the stack. No flags are affected.
The CALL and RET instructions allow the possibility of subroutines. A subroutine is a part of a program which performs a
function that is needed in many different parts of the main program. The CALL instruction jumps to a subroutine after
putting on the stack the address of the instruction following the CALL. The subroutine's last instruction executed will be a
RET which will cause the program to return to the address that is on the stack. Later in this manual there are some
example programs which use subroutines that are built in the MOS.
The following program uses a subroutine which outputs the value in the A register to the digital output LEDs and delays for
a period of time proportional to the value in HL.
leds
equ
org
lxi
loop:
mvi
call
cma
call
mvi
call
dcr
jmp
delay:
push
push
out
delay1:
dcx
mov
ora
jnz
pop
pop
ret
end
ADDRESS
FF01
FF02
FF03
FF04
FF05
FF06
FF07
FF08
FF09
FF0A
FF0B
FF0C
continued on next page...
op code = C9
op code = 25
op code = C5
11h
; ouput port address for LEDs
0ff01h
h,8000h
; starting delay length
a,00001111b ; bit pattern for 4 left LEDs lit.
delay
; output the bit pattern and delay
; complement A
delay
; output the bit pattern and delay
a,01010101b ; pattern for lighting odd# LEDs
delay
; output the bit pattern and delay
h
; decrease the delay
loop
; jump to loop
h
; save HL on stack
psw
; save A register & flags on stack
leds
; output pattern in A to LEDs
h
; decrement delay length
a,h
; A=H so H it can be ORed with L
l
; H
ORed with L is 0 if HL=0000
delay1
; if HL>0 then jump to delay1
; Registers are POPed in reverse order of PUSHes
psw
; restore A register and flags
h
; restore HL register
; return to instruction after the CALL
DATA
INSTRUCTION
21
LXI
H,8000
00
80
3E
MVI
A,0F
0F
CD
CALL FF16
16
FF
2F
CMA
CD
CALL FF16
16
FF
63

Advertisement

Table of Contents
loading

Table of Contents