What is the total # of clock cycles requried for the following codes: LDX #14 ;
ID: 2080921 • Letter: W
Question
What is the total # of clock cycles requried for the following codes:
LDX #14 ; 2 Cycles
DELAY DEX ; 1 Cycle
BNE DELAY ; 3 (back) / 1 (down) cycle(s)
The total number of clock cycles :_________________ ( please explain what formula you use, or you get it)
My quesitons is how do you calculate the total clock cycle based on Delay....
There is another similar total # of clock cycles problem. Please help!
LDX #20 ; 2 cycles
DELAY: DEX ; 1cycle
BNE DELAY ; 4 (back) / 2(down) cycle(s)
Thank you very much!
Explanation / Answer
The time taken for an instruction to be executed is given by its clock cycle. The duration of a clock cycle varies according to the frequency of the processor which we are not interested right now. First let me explain the function of the three instructions given in the question
As per our question the instruction DEX decreases the register X from 14 to 0 only if it is called 14 times. So the loop has to run for 14 times. The number of machine cycles for one loop = 1(DEX)+3(BNE)=4 Cycles.
The number of machine cycle the instruction LDX = 2 cycles
For 13 loops, the total number of machine cycle = 13*4=52 cycles
At 14th loop, the total number of machine cycles = 1(DEX)+1(BNE)= 2 cycles (At 14th loop, DEX results zero, and the zero flag is set. BNE makes the program come out of the loop. It takes just one cycle)
Total number of cycles = 2+52+2=56 cycles
For question number 2, BNE takes 4 cycles if zero flag is not set and 2 cycle if zero flag is set. DEX has to be called 20 times to decrement to 0.
The number of machine cycle the instruction LDX = 2 cycles
For 19 loops, the total number of machine cycle = 19*(1+4)=95 cycles
Last loop = 1+2=3
Total number of cycles = 2+52+2=100 cycles
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.