Writing Program for DJNJ Instruction in Assembly Language
Using Decrement and Jump Not Zero (DJNZ) in Assembly Language
The DJNZ (decrement and jump if not zero) instruction is a conditional jump statement in assembly language syntax that allows for loop control. It decrements a register, and then tests the contents of the register to determine whether to execute a jump. If the contents of the register are not equal to zero, the jump is taken; otherwise, normal program execution continues.
Program
This program will print out the numbers from 1 to 10 using a DJNZ instruction.
MOV R1, #9 ; load starting value into register loop: PRINT R1 ; print value DJNZ R1, loop ; decrement and jump if not zero
The program starts by loading the starting value, 9, into register R1. Then it prints this value to the screen. Finally, it decrements the value in R1 and checks if it is not zero. If it is not zero, the DJNZ instruction jumps back to the start of the loop and prints out the value again. If the value is zero, the program execution continues to the instruction following the loop.