# MIPS Number of Instructions Executed and Memory Accessed

## Homework Statement

The number of instructions a program has is the static instruction count. The number of instructions actually executed (e.g. due to some instructions being repeated, as in a loop) is called the dynamic instruction count. Consider the following code:
li $t0, 99 li$t1, 44
loop: addi $t0,$t0, -1
lw $t1, 0($t1)
bne $t0,$zero, loop
add $v0,$t0, $zero a. What is the static instruction count of this code? What is the dynamic instruction count? (Assume any pseudoinstructions are counted as 1 instruction). b. How many times is the instruction memory accessed? How many times is the data memory accessed? c. Assuming this runs on a single cycle processor (with CPI = 1) running at 100 KHz, how long will the code take to execute? ## Homework Equations [/B] Execution Time = (CPI * IC) / Clock Rate ## The Attempt at a Solution a. Static Instruction Count: 6 (Since there are only 6 instructions in the code.) Dynamic Instruction Count: (99 * 3) - 1 + 3 = 299 (The two li instructions and the add instruction only executed once. The loop itself executes 99 times but bne instructions executes only 98 times since at the 99th iteration,$t0 = 0 and bne instruction won't executed.)

b. Instruction Memory Accessed: 299 (Number of times program counter updated)
Data Memory Accessed: 99 (Number of times lw or load instruction was executed)

c. Given CPI = 1, IC = 299 (from part a), Clock Rate = 100000 (Converted KHz to Hz)
Execution Time = (1 * 299) / 100000 = 2.99 x 10-3 milliseconds

I am not sure if I calculated the Dynamic Instruction Count correctly and if the Instruction Memory Accessed is correct or not. Any input would greatly appreicated.

Last edited:

Related Engineering and Comp Sci Homework Help News on Phys.org
Merlin3189
Homework Helper
Gold Member
... but bne instructions executes only 98 times since at the 99th iteration, \$t0 = 0 and bne instruction won't executed.)
BNE executes every time. The duration may vary, but I think here you are not asked to consider that.

Perhaps you could say what processor this is, so that we can look up details.

It's the MIPS processor.