If a loop might need to run 0 times, put a conditional branch outside the loop to check for that case.
You can also put some instructions to set up for (or actually do some of) the first iteration outside the loop. Another trick is to jump into the middle of the loop instead of falling into the first instruction. I'm not sure if there's a name for this technique. (Wikipedia defines software pipelining as something more complex that increases code size, instead of just rotating the sequence of instructions inside the loop while adjusting the code outside to match.)
Then restructuring to put the loop condition at the bottom is straightforward: invert the check so fall-through out of the loop happens when appropriate, instead of taking the branch to exit.
If you really want to reduce the number of instructions executed, you can just do some math and eliminate the loop. $t0 = 0 .. $a-1
, and you add that to $v0
every iteration. So the loop is just a sum(0..$a-1). There's a closed-form formula for sum(0..n): n * (n+1) / 2
.
Note that you can skip the $t0 = 0
iteration when transforming your loop (if you decide to keep it), since 0 is the additive identity.