You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Matthew Faltys b28872238d Fix strange formatting bug 5 years ago
examples Add class examples 5 years ago
.gitignore Add gitignore for swap files 5 years ago
Makefile Add makefile to use spim mips simulator 5 years ago
prj1.asm Fix strange formatting bug 5 years ago
readme.md Add documentation for prj1.asm 5 years ago

readme.md

Project 1

The source code for this project is documented line-by-line but I will go over a broad approach here.

At the time of writing there are 2 functions: main and lookup:

Main

The main function takes some user input (for argument 2, the number to be found) and stores it into register $a1 (which is the argument register to send to lookup). At the same time we set $a0 and $a2 which are the base address of array, and the max index of the array to check (respectively). When main is returned to after the lookup function it outputs the result (either the index where the value is found, or -1) and prints it to screen. The last thing main does is make the exit syscall to stop the program.

Lookup

The lookup function takes 3 arguments: $a0, $a1, $a2 (mentioned above). The first thing the function does is make a temporary register with a value equalling one more than the maximum array index we will check (this way we can determine if the function is out of bounds). We then check for the out of bounds (oob) case and return a -1 and jump back to where we left in main ($ra). If we pass the oob check we continue the loop by finding the current index in the array and comparing it with the value that was passed to us in $a1. If we find the proper value we jump back to $ra while passing back the index where we found it, otherwise we increment the array index counter and loop back to the start of the lookup function.

At the bottom of the program is where we store all our data values (hence the .data tag). This is where the array and all our messages are to be used in the program.