Department of Computer Science and Information EngineeringNational Cheng Kung University, TAIWAN
HANELLOOP AND JUMP INSTRUCTIONSLooping
Repeating a sequence of instructions a certain number of times is called a loop
¾Loop action is performed by DJNZ reg, Label
The register is decrementedIf it is not zero, it jumps to the target address referred to by the labelPrior to the start of loop the register is loaded with the counter for the number of repetitionsCounter can be R0
- R7 or RAM location
;This program adds value3 to the ACC ten timesMOV A,#0 ;A=0, clear ACCMOV R2,#10 ;load counter R2=10
AGAIN: ADD A,#03 ;add 03 to ACCDJNZ R2,AGAIN ;repeatuntil R2=0,10 timesMOV R5,A ;save A in R5A loop can be repeated a maximum of 255 times, if R2 is FFH