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
j which makes it $99⋅3$ and then $2$ for
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?