How many times will the following loop be executed What is t
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
2.Ans
a. 11.0592 Mhz
the crystal is pulsing 11,059,000 times per second and that one machine cycle is 12 pulses,
one machine cycle takes 12/11059000 = 1.085*10^-6 s
b.
16 Mhz
the crystal is pulsing 16,000,000 times per second and that one machine cycle is 12 pulses,
one machine cycle takes 12/16000000= 0.75*10^-6 s
c.
12 Mhz
the crystal is pulsing 12,000,000 times per second and that one machine cycle is 12 pulses,
one machine cycle takes 12/12000000= 1*10^-6 s
