djnz
Decrement B and jump if not zero
Decrements B and jumps to the target when B is not zero.
2 bytes · 13/8 cycles13 cycles when it jumps, 8 when it does not
Used in
- Loops and djnzZ80 assembly
- Arrays, strings and ixZ80 assembly
- The stack, push and popZ80 assembly
- call, ret and passing valuesZ80 assembly
- Fill an array with the numbers from 1 to 10Z80 assembly
- Sum of an arrayZ80 assembly
- The largest elementZ80 assembly
- Reverse a string in placeZ80 assembly
- Multiply and divide, with the remainderZ80 assembly
- Even or odd, count the set bits, multiply by shiftingZ80 assembly
SZHP/VNC ––––––
- Changes no flag
Forms
djnzThe B register is decremented, and if not zero, the signed value
offsetis added to PC. The jump is measured from the start of the instruction opcode.
Operands
offset- A relative-jump target, written as a label or address. The assembler calculates the displacement,
-128to127, and reports an error if the target is out of range. More
.org 0x8000
ld b, 3
loop: djnz loop
halt