
<
2
.75
7UGT U/CPWCN
#FFTGUU5RCEG
=L/2*
7/<:
DJNZ
Decrement And Jump If Non-zero
Instruction Format:
DJNZ r, dst
Operation:
r
←
r - 1;
If r
≠
0, PC
←
PC + dst
The specified working register serves as a counter and is decremented. If the contents of the specified working
register are not
0
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 relative address is
+127
to
–
128
. The original value of the PC is the address of the instruction byte following the
DJNZ
statement. When
the specified working register counter reaches
0
, control falls through to the statement following the
DJNZ
instruction.
Flags:
When the instruction is executed, the flags are set as follows:
Example:
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:
1.
Load
12
into the counter (working register
R6
).
2.
Set up the loop to perform the moves.
3.
End the loop with a
DJNZ
instruction.
C:
The value set by the preceding instruction.
Z:
The value set by the preceding instruction.
S:
The value set by the preceding instruction.
V:
The value set by the preceding instruction.
D:
The value set by the preceding instruction.
H:
The value set by the preceding instruction.
r
OPC
dst
OPC (Hex)
Address Mode
dst
rA
(r=0 to F)
RA