1.7 KiB
Project 1
- You can see this project in action at https://git.unixvoid.com/mfaltys/CSCI-4350
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.