15 pts 3 A Compiler designer is trying to decide between two
Solution
1.Which code sequence executes the most instruction ?
Let\'s count the number of cycles needed to execute each code:
First code sequence: No. of cycles = 2x1 + 1x2 + 2x3 + 2x5 = 20 cycles.
Second code sequnce : No. of cycles = 4x1 + 1x2 + 2x3 +1x5 = 17 cycles.
Therefore the firstcode sequence executes the most instruction.
2.Which code squence will be faster?
Let\'s count the number of cycles needed to execute each code:
First code: No. of cycles = 2x1 + 1x2 + 2x3 + 2x5 = 20 cycles.
Second code: No. of cycles = 4x1 + 1x2 + 2x3 +1x5 = 17 cycles.
Therefore the second code is faster because it requires less number of cycles to execute.
(# cycles 1)/(# of cycles 2) = 20/17 = 1.17…
Therefore the second code 2 is faster than the first code by 1.17 times.
3.What is the overall CPI for each squence?
CPI1= CPU_cycles1/ Instruction_count1= 20/7 = 2.8
CPI2= CPU_cycles2/ Instruction_count2= 17/8 = 2.1
