How many times will the following loop be executed What is t

How many times will the following loop be executed? What is the total number of Machine Cycles for this subroutine assuming a standard 8051 processor at 11.0592 MHZ? (Machine cycles, MOV – 1, DJNZ – 2, RET- 2)

DELAY: MOV R5, #100

BACK: MOV R2, #200

HERE: DJNZ R2, HERE

DJNZ R5, BACK

RET

Solution

HERE: DJNZ R2,HERE ; decrements R2 by 1 and if R2 is non zero goes to here, like wise loop runs for 200 times

DJNZ R5,BACK ; decrements R5 by 1 and if R5 is non zero goes to BACK, like wise this loop runs for 100 times, for each loop R2 initializes with 200 and iterates 200 times, so total iterations would be 200*100

Machine cycles:

DELAY: MOV R5,#100 ; 1 machine cycle

BACK: MOV R2,#200 ; 1 machine cycle

HERE: DJNZ R2,HERE; 2 machine cycles (200*2)

DJNZ R5,BACK ; 2 machine cycles

RET ; 2 machine cycles

total = 1(DELAY: MOV R5,#100)+1(BACK: MOV R2,#200)+((200*2)(HERE: DJNZ R2,HERE;)+1*2(DJNZ R5,BACK)+1(BACK: MOV R2,#200))*100(times)+2(RET)

total = 1+1+(400+2+1)*100+2

=40304 machine cycles

total delay is 40304*(12/11059000) = 0.0437 sec

How many times will the following loop be executed? What is the total number of Machine Cycles for this subroutine assuming a standard 8051 processor at 11.0592

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site