Welcome to my MIPS reference guide! This is a collection of code snippets and brief explanations for various things in MIPS that you will be doing often. It assumes at least basic knowledge of MIPS syntax.
Note that I (Jesse) am just doing this as a side project for fun, and can’t make guarantees about how quickly things get updated, etc.. In other words it shouldn’t be considered an “official” part of the class.
Explanations and comments will frequently reference the C language.
As a super brief overview of C syntax when working with pointers (memory addresses)…
int myVal = 10; // define an int.
int *intPointer; // declare an int pointer.
intPointer = &myVal; // set the pointer to contain the memory "address of" (&) myVal.
*intPointer = 20 // "dereference" (*) the pointer and set the value at that memory address to 20
// dereferencing means:
- instead of reading/writing the memory address, we read/write the value located at that memory address.
// at this point in the code, myVal == 20, because we updated it via the pointer.
I don’t know where to throw this little snippet so it’s just going here for now.
# Say we want to set $t0 to 1
# We can simply use the addi instruction to add $zero and the number we want.
# The $zero register is just a register that always equals 0. It's quite useful.
addi $t0, $zero, 1 # int t0 = 1
# you can also enter hexadecimal values
addi $t2, $zero, 0xFA7 # int t2 = 0xFA7