Download Print this page

ZiLOG Z80 Handbook page 225

Hide thumbs Also See for Z80:

Advertisement

TIMING LOOP
A timing loop may be used for a variable time delay for I / O proc-
essing, real-time interval timing , or a delay for operator response.
It is convenient to have a timing loop that will run from milliseconds
to 30 seconds or so. If the average instruction execution time is 2.5
µs (4-Mhz clock ), then 12,000,000 instructions will have to be exe-
cuted for a 30-second delay. A two-level nested loop will work if
each segment of the loop can delay about 3 ,000 counts or if one can
delay 300 counts , while the other delays 30,000 counts.
DELAY
LD
DE,-1
FOR DECREMENT
LOOPI
LD
HL,14814
INITIALIZE INNER LOOP
LOOP2
ADD
HL,DE
HL - 1
JR
C,LOOP2
GO IF NOT 0
DJNZ
LOOP1
RET
The inner loop above takes 0.1 second to decrement HL from
14814 to 0. The outer loop is determined by the B register input
value so that:
DELAY = ( B) x 0.1 sec. approximately
The maximum delay is 25.6 seconds with B = 256 , but longer delays
can be implemented by altering the initialization value of HL.
MULTIPLY AND DIVIDE SUBROUTINES
An 8-bit by 8-bit unsigned multiply was discussed in Chapter 12.
The operands in this multiply are somewhat limited for many appli-
cations. A 16-bit by 16-bit multiply would handle most microcom-
puter applications; if more precision were required, a floating point
multiply would have to be implemented. In the 16-bit by 16-bit
multiply below, the multiplier is input in DE, unsigned, and the mul-
tiplicand is in BC, unsigned. The 4-byte output is passed in D, E, H,
and L. Overflow is not possible.
MULT16
LD
A,16
ITERATION COUNTER
LD
HL,O
ZERO PRODUCT
LOOP
BIT
7,D
TEST NEXT M'IER BIT
JP
Z,JUMP1
GO IF 0
ADD
HL,BC
ADD M'CAND
JP
NC,JUMP1
GO IF NO CARRY
JUMP1
INC
DE
CARRY TO MS BYTES
DEC
A
DECREMENT ITERATION COUNT
RET
Z
RETURN
EX
DE,HL
234

Advertisement

loading
Need help?

Need help?

Do you have a question about the Z80 and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel