How many instruction cycles does it take to execute the following instructions?
ID: 3891821 • Letter: H
Question
How many instruction cycles does it take to execute the following instructions? start tracing here.. mov #2, W0 mov #3, WI mov #6, W2 add WO , WI , WI cp Wl, W2 bra LTU, loop loop : end_loop: mov W1, ul6 a stop tracing here.... 13. Instruction cycles:13)'. 14. Show your work mov #2, wo: 1 cycle (wo-2) mov #3, w 1:1 cycle (W 1-3) mov #6, w2: 1 cycle(w2-6) loop: add wo, W1, W1: 1 cycle (Wi-5) cp W1,W2: 1 cycle (Z-0, C-0) bra LTU, loop: 4 cycles (taken) loop: add wo, wi, Wi: 1 cycle (Wi-7) cp W1,W2: 1 cycle (Z-0, C 1) bra LTU, loop: 1 cycle (not taken) end loop: mov W1, u16 _a: 1 cycleExplanation / Answer
the mov commands are all 1 instruction cycles each. The add command and the cp belong to the loop. They each take 1 cycle and since the loop gets executed twice they collectively add 2 instruction each. So up till now we have 3 + 2X2 = 7 cycles.
In the first few iterations, The BRA LTU jumps to the loop as cp initiates Z and C flag to 0 and this takes 4 cycles, but in the next iteration, when cp initiates C flag = 1 as W1 > W2 so BRA LTU doesn't get jumps to loop. This is meant by not taken in the explanation and takes only 1 cycle. So this further takes 5 instruction cycles.
Finally the mov also contributes 1 cycle and therefore our final count is :
7 + 5 + 1 = 13 cycles.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.