# How do I count the exact number of executed commands for a MIPS program?

I want to know what the best way is to count the number of executed commands for a given MIPS program. Let's say we're given a simple for loop that counts from $$0$$ to $$100$$. For this I would write the following MIPS code:

li $$s1, 0 li$$t0, 100

for_loop:
addi $$s1,$$s1, 1
beq $$s1,$$t0, exit
j for_loop

exit:


Since I have $$2$$ li's before the loop, that would be $$+2$$ commands and then within the for_loop, the 99 loops pass for addi, beq and j which makes it $$99⋅3$$ and then $$2$$ for addi and beq. That makes it a total of $$301$$ executed commands. Is my answer correct? If not then what is the correct procedure to count the number of executed commands and if in the future I come across a more complex example, then how should I deal with it?

• We discourage "please check whether my answer is correct" questions, as only "yes/no" answers are possible, which won't help you or future visitors. See here and here. It's usually better to ask about a specific conceptual issue you're uncertain about. As a rule of thumb, a good conceptual question should be useful even to someone who isn't looking at the problem you happen to be working on. If you just need someone to check your work, you might seek out a friend, classmate, or teacher. – D.W. Jan 8 at 23:04

Sometimes you’re lucky to get a result like “about 2.25 n^2”, or “$$\Theta (n^2)$$ or similar. How do you deal with it? You do your best.
• That makes sense but I also want to know how to do it manually. Therefore is my answer of $301$ correct? – xxxtentacion Jan 6 at 15:03