How do I count the exact number of executed commands for a MIPS program?
There are two ways: You use a simulator and count the actual number of instructions (or do it manually), which of course only works for fixed input like your case here. Or you use mathematics to calculate the number of instructions, just as you did. 

In general, mathematical analysis ranges from easy to hard to impossible for humans, so there is no general method. 

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.