![](http://datasheet.mmic.net.cn/360000/Z80B-CTC_datasheet_16678678/Z80B-CTC_171.png)
Z8 Microcontrollers
ZiLOG
Instruction Descriptions and Formats
UM001600-Z8X0599
12-31
DJNZ
DECREMENT AND JUMP IF NON-ZERO
DJNZ
Decrement and Jump if Non-zero
DJNZ r, dst
Instruction Format:
Operation:
r <— r - 1;
If r <> 0, PC <— PC + dst
The specified Working Register being used as a counter is decremented. If the contents of the specified
Working Register are not zero after decrementing, then 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
following the DJNZ statement. When the specified Working Register counter reaches zero, control falls
through to the statement following the DJNZ instruction.
Note:
The Working Register being used as a counter must be one of the Registers from 04H to EFH. Use of
one of the I/O ports, control or peripheral registers will have undefined results.
Example:
DJNZ is typically used to control a “l(fā)oop” of instructions. In this example, 12 bytes are moved from one
buffer area in the register file to another. The steps involved are:
Load 12 into the counter (Working Register R6).
Set up the loop to perform the moves.
End the loop with DJNZ.
The assembly listing required for this routine is as follows:
r
dst
12 if jump taken
10 if jump not taken
Cycles
OPC
(Hex)
Address Mode
dst
rA
RA
(r = 0 to F)
OPC
Flags:
C:
Z:
S:
V:
D:
H:
Unaffected
Unaffected
Unaffected
Unaffected
Unaffected
Unaffected
LD R6, 12
LD R9, @R6
;Load Counter
;Move one byte to
LOOP
:
LD @R6, R9
DJNZ R6,
LOOP
;new location
;Decrement and Loop until
counter = 0