8051 Instruction Set Manual

DJNZ

The DJNZ instruction decrements the byte indicated by the first operand and, if the resulting value is not zero, branches to the address specified in the second operand.

Note

When this instruction is used to modify an output port, the value used as the port data is read from the output data latch, not the input pins of the port.

See Also: CJNE

DJNZ direct, offset
CACF0RS1RS0OV P
Bytes3
Cycles2
Encoding
11010101directoffset
Operation
DJNZ
PC = PC + 2
(direct) = (direct) - 1
IF (direct) <> 0
  PC = PC + offset
Example
DJNZ 40h, LABEL
DJNZ Rn, offset
CACF0RS1RS0OV P
Bytes2
Cycles2
Encoding
11011nnnoffset
Operation
DJNZ
PC = PC + 2
Rn = Rn - 1
IF Rn <> 0
  PC = PC + offset
Example
DJNZ R6, LABEL