Due Friday, January 29 at 11:59:59 PM
By the time you have completed this work, you should be able to:
There are three tasks that you need to complete for this week, some with multiple steps. Strictly speaking, you may complete them in any order, though for this lab it is recommended to go in order. The tasks are listed below:
You may use any MIPS instructions or psuedoinstructions you want in order to implement these tasks. However, you will be somewhat restricted on exams. You may want to read the grading policies regarding MIPS assembly instructions for more information.
The initial step below describes how to get the files you will need into the appropriate place. These files are used for all the different tasks.
After you log in, go into your cs64
directory that you created last time:
cd cs64
Then create a new directory for this lab: lab3
:
mkdir lab3
Then go into that directory.
Now copy over all of the files necessary for this week's tasks:
cp ~kyledewey/public_html/cs64/labs/3/MedianNumbers.asm ~kyledewey/public_html/cs64/labs/3/task1_tester.pl ~kyledewey/public_html/cs64/labs/3/factorial.asm ~kyledewey/public_html/cs64/labs/3/task2_tester.pl ~kyledewey/public_html/cs64/labs/3/partner.txt .
Note the use of the trailing .
in the above command, which stipulates that the specified files should be copied into the current directory.
This task requires you to use branches in MIPS assembly. To this end, you will write a MIPS program which will ask the user for three numbers and then print out the median. A sample run of this program will look like this, with user input in bold:
Enter the next number: 3 Enter the next number: 5 Enter the next number: -13 Median: 3
Your code should be written in the provided MedianNumbers.asm
template file.
Be sure that your output matches exactly with the output above.
Note that you do not need to use a complex sorting algorithm because you are only comparing exactly 3 numbers, not some arbitrary number of numbers. A good development strategy here is to write a small program in C that will behave the same way as the program above, and to test it out. From there, it can be ported to assembly, which should be simpler than directly writing in assembly (considering that you are just starting to write in assembly). Try to write as simple of C code as possible, as ultimately any complexity in C will almost certainly translate to complexity in assembly.
For your convenience, we have provided a handful of test cases for you. These can be run from the CSIL machines with the following command:
./task1_tester.pl
The provided test cases are hardly complete; you are encouraged to add your own test cases and perform your own testing.
This task requires you to write a basic loop in MIPS assembly. To this end, you will implement the factorial function iteratively (i.e., without using recursion), which will take as an input some number gathered from the user. The factorial function will print out all the partial products as they are encountered, along with the final result. Each of the printed out numbers should be followed by a newline. Pseudocode showing how to do this is shown below:
n = <<user input>> accum = 1 while (n != 0) { accum = accum * n print accum print “\n” n = n - 1 } print accum print “\n”
A sample run of the program on input 1
is shown below, with user input in bold:
Enter the number: 1 1 1
A second run of this program on input 0
is shown below, with user input in bold:
Enter the number: 0 1
A third run of this program on input 5
is shown below, with user input in bold:
Enter the number: 5 5 20 60 120 120 120
You should write your program in the provided factorial.asm
template file.
For full credit, your solution's output must match the above output exactly. Additionally, while you may write your own algorithm to do this, it must be iterative; that is, you may not use recursion. You may assume that the user will only input non-negative numbers, and that no multiplication will lead to overflow. You will be working only with unsigned integers for this task.
For your convenience, we have provided a handful of test cases for you. These can be run from the CSIL machines with the following command:
./task2_tester.pl
The provided test cases are hardly complete; you are encouraged to add your own test cases and perform your own testing.
turnin
If you partnered with someone, record the email address they are using for the class in partner.txt
.
For example, if your partner had the email address foo@bar.com, then the contents of partner.txt
should be the following (and only the following):
Partner: foo@bar.com
If you did not partner with anyone, you do not need to (and should not) edit partner.txt
.
Assuming you are in the cs64/lab3
directory you created at the beginning, you can send in your answers via the following command:
turnin lab3@cs64 MedianNumbers.asm factorial.asm partner.txt
You may turn in the same assignment up to 100 times, which is useful if you are working on it incrementally. Note that only the last version you submitted will be graded.
Even if you did not partner with anyone, you should still turn in partner.txt
, which should not have been modified.
Prepared for Computer Science 64 by Diana Franklin, with slight adaptation by Kyle Dewey.