DJNZ
Decreases register B by 1 and jump if Zero (Z) flag is not set. This is a relative jump (see JR ) so there is a restriction of -128 to +127 byte range for address of the jump.
Note that DJNZ will only work with register B but is a lot more efficent than using two instructions such as dec b than jr {label|address|??}.
| Instruction | Description | Opcode |
|---|---|---|
| DJNZ {label|address|??} | If the Zero (Z) flag is not set then decrement and jump relative | 10 {??} |
Example
In this example, we loop through two loops counting down from 5 to zero. The inside loop count is reset each time.