ZiLOG Z8 Technical Manual page 54

Microcomputer
Hide thumbs Also See for Z8:
Table of Contents

Advertisement

DJNZ
Decrement and Jump
if
Nonzero
DJNZ r,dst
Instruction format:
Cycles
OPC
(Hex)
Address Mode
dst
~
___ r __
~
___ o_p_C __
~1 I~
_____
d_s_t ______
~
12
i f
jump taken
10
if jump not taken
rA
RA
Operation:
flags:
Exaq>le:
Note:
5-20
r=O to
r
r
<--
r - 1
If r
~
0, PC
<--
PC
+
dst
The working register being used as a counter is decremented.
If the contents of the
register are not zero after decrementing, the relative address is added to the
Program Counter (PC) and control passes to the statement whose address is now in the
PC.
The range of the relative address is +127, -128, and the original value of the
PC is the address of the instruction byte following the DJNZ statement.
When the
working register counter reaches zero, control falls through to the statement
following DJNZ.
No flags affected
DJNZ is typically used to control a "loop" of instructions.
In this example, 12
bytes are moved from one buffer area in the register file to another.
The steps
involved are:
o Load 12 into the counter (working register 6)
o Set up the loop to perform the moves
o End the loop with DJNZ
LD R6,
1112
LOOP: LD R9,OLDBUr (R6)
LD NEWBUr (R6),R9
DJNZ R6,LOOP
!Load Counter!
!Move one byte to!
!New location!
!Decrement and !
!Loop until counter
O!
The working register being used as a counter must be one of the registers 04-7F.
Use of one of the I/O ports, control or peripheral registers will have undefined
results.

Advertisement

Table of Contents
loading

Table of Contents