S3C84I8/F84I8/C84I9/F84I9
DJNZ
— Decrement and Jump if Non-Zero
r,dst
DJNZ
r ← r – 1
Operation:
If r ≠ 0, PC ← PC + dst
The working register being used as a counter is decremented. If the contents of the register are
not logic zero after decrementing, the relative address is added to the program counter and
control passes to the statement whose address is now in the PC. The range of the relative
address is + 127 to – 128, and the original value of the PC is taken to be the address of the
instruction byte following the DJNZ statement.
In case of using DJNZ instruction, the working register being used as a counter should be set at the one of
NOTE:
location 0C0H to 0CFH with SRP, SRP0 or SRP1 instruction.
No flags are affected.
Flags:
Format:
r | opc
Given: R1 = 02H and LOOP is the label of a relative address:
Example:
SRP
DJNZ
DJNZ is typically used to control a "loop" of instructions. In many cases, a label is used as the
destination operand instead of a numeric relative address value. In the example, the working
register R1 contains the value 02H, and LOOP is the label for a relative address.
The statement "DJNZ R1, LOOP" decrements the register R1 by one, leaving the value 01H.
Because the contents of R1 after the decrement are non-zero, the jump is taken to the relative
address specified by the LOOP label.
Bytes
dst
2
#0C0H
R1,LOOP
Cycles
Opcode
8 (jump taken)
8 (no jump)
r = 0 to F
INSTRUCTION SET
Addr Mode
(Hex)
dst
rA
RA
6-39