4/17/98 6-95 Addressing Modes and Data Types
DJNZ Decrement and jump if not zero
Syntax: DJNZ dest, rel8
Operation: (PC) <-- (PC) + 3
(dest) <-- (dest) - 1
if (Z) = 0 then
(PC) <-- (PC + rel8*2); (PC.0) <-- 0
Description: Controls a loop of instructions. The parameters are: a condition code (Z), a counter
(register or memory), and a displacement value. The instruction first decrements the counter by
one, tests the condition if the result of decrement is 0 (for termination of the loop); if it is false,
execution continues with the next instruction. If true, execution branches to the location indicated
by the current value of the PC plus the sign extended displacement. The value in the PC is the
address of the instruction following DJNZ.
The branch range is +254 bytes to -256 bytes, with the limitation that the target address is word
aligned in code memory.The destination operand could be byte or word.
Note: Refer to section 6.3 for details of jump range
Size: Byte, Word
Flags Updated: N, Z
DJNZ Rd, rel8
Bytes: 3
Clocks: 8t/5nt
Encoding:
byte 3: rel8
DJNZ direct, rel8
Bytes: 4
Clocks: 9t/5nt
Encoding:
byte 3: lower 8 bits of direct
byte 4: rel8
1 0 0 0 SZ 1 1 1
d d d d 1 0 0 0
1 1 1 0 SZ 0 1 0
0 0 0 0 1 direct: 3 bits