
THE 8051 MICROCONTROLLER: THE PROGRAMMER’S PERSPECTIVE 19-43
ORG 0
MOV R1,45H ;take data from RAM address 45H
MOV R3,#8 ;R3 to act as a counter for 8 bits
MOV R2,#0 ;R2 = 0
MOV A,R1 ;copy R1 to A
ROT: RLC A ;rotate left
JNC COUNT ;if C = 0, jump to COUNT
INC R2 ;since C = 1, increment R2
COUNT: DJNZ R3,ROT ;decrement until R3 = 0
HERE: SJMP HERE
END
19.11 | Subroutines (Procedures)
All the programs that we have written are straightforward, in the sense that control flows
sequentially from one instruction to the next, and a change in the sequence in which a
program is executed, is changed only on encountering a JUMP instruction. ...