First of all, you need a cheat sheet: MIPS Instruction Reference
A good reference sheet is the most useful thing possible when writing assembly for any architecture.
Secondly, start breaking the program down on the high level. You know the functions and their names, so start there. Start by defining the functions and creating a very basic definition for each function so that it is actually callable.
Next, write the code that will pull the function parameters from their respective places for each function. You are lucky here as each function just accepts a basic integer. You will need to move any function parameters into $a0
- $a3
before calling the function. You can then write the code that moves your return value into $v0
or $v1
before returning. Make sure in each function you write, you save off the registers you are using onto the stack and then restore them before your jal $ra
. Now you should have some functions that are callable and return values, but don't really do anything.
Lastly, actually write the junk that your functions do. Again, you are luck as you are only using int
... so each number will match to one register and you will only need to offset by 4 bytes when referencing the stack... making things easier. I'll give you a hint for int sub(int a, int b)
... it'll look something like this:
sub $t2, $t1, $t0
Haha, see? It's not so hard to write assembly :D
Of course you will then have to move your result into $v0' or
$v1` at the end of the function and jump back to the callee.
Anyways, hope that gets you started.