Due Thursday, July 6 at 11:59 PM
By the time you have completed this work, you should be able to:
if
/else
) and loops (while
, for
) into MIPS assemblylw
instructionsw
instructionfactorial.asm
Open the factorial.asm
file with a text editor of your choice.
Note that word processors (e.g., Microsoft Word, Pages, Google Docs) will probably not work for this purpose, as you must save your file as plain text.
You must write MIPS assembly code which, when run under QtSpim, will do the following:
An example interaction with this program is shown below:
5 120
factorial.asm
contains comments which further explain how you can do this.
You may assume that the input integer will be non-negative.
You may also assume that the computed factorial will fit into a 32-bit unsigned value, so you never need to look at the HI
register.
The Week 5 Materials have some examples which may be helpful.
sum.asm
Now move to the sum.asm
file.
This program contains a hard-coded array, along with its length, in the .data
section of the file.
You must iterate through this array, compute the sum of all the elements (i.e., add them all together), and print out the result.
Given the existing data in the file, this program should print 28
.
Your code should work for ANY array
and array_length
values, but you may assume the following:
array_length
will always be at least 1, and will be an unsigned integerarray
will contain exactly as many .word
s as array_length
.
Further details are provided in the comments of sum.asm
.
The Week 5 Materials have some examples which may be helpful.
add_amount.asm
Now move to add_amount.asm
.
This program works with two arrays of the same length: an input array, and an output array.
Additionally, it contains a value to add to each element of the array (amount_to_add
).
For each element of the input array, it should add this amount, putting the result in the output array.
A code snippet below illustrates this behavior:
for (int index = 0; index < array_length; index++) { output_array[index] = input_array[index] + amount_to_add; }
The end of the code (provided) will print each element of the output array.
As with the prior problem, this code MUST work for any values of amount_to_add
, array_length
, input_array
, and output_array
.
You may make the following assumptions in your code:
array_length
will always be at least 1, and will be an unsigned integerinput_array
and output_array
will always contain exactly array_length
.word
s.input_array
will all be non-negative.amount_to_add
will always be an unsigned integer.The Week 5 Materials have some examples which may be helpful.
Log into Canvas, and go to the COMP 122 class.
Click “Assignments” on the left pane, then click “Lab 5”.
From here, you can upload your .asm
files.
Specifically, you must turn in the following three files:
factorial.asm
sum.asm
add_amount.asm
In addition, if you collaborated with anyone else, be sure to download collaborators.txt
and write the names of the people you collaborated with in the file, one per line.
Please submit this file along with the other three files.
You can turn in the assignment multiple times, but only the last version you submitted will be graded.
The code you submit must run under QtSpim without modification.
Code with syntax errors gets an automatic 0.
If you can't get your code to do the right thing, it's better to submit code that runs but does the wrong thing.