Repeating a sequence of instructions a certain number of
times is called a LOOP
The loop is one of most widely used actions that any
microcontroller performs
MOV A,#0
MOV R2,#10
AGAIN:
ADD A,#25
DJNZ R2,AGAIN
MOV R5,A
In this program R2 is used as counter. The counter is
first set to 10. In each iteration the
instruction DJNZ decrements R2 and checks its value. If R2 is not zero it jumps
to the target address associated with the label “AGAIN”. This looping action
continues until R@ becomes zero. After R2 becomes zero, it terminates the loop
and executes the instruction immediately below it, in this case the MOV
R5,A
No comments:
Post a Comment