lab03 : Basic MIPS Operations

num ready? description assigned due
lab03 true Basic MIPS Operations Thu 01/24 08:00AM Mon 01/28 11:59PM

Lab 3: MIPS Instructions for Basic Arithmetic and Using Standard I/O


Due Monday, January 28th

Goals for This Week

By the time you have completed this work, you should be able to use basic arithmetic and standard I/O calls in MIPS assembly.

Provided files:

Documentation:


Step by Step Instructions

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.

Initial Step: Create a Directory for This Lab and Copy Over the Files

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 ~zmatni/public_html/cs64w19/labs/3/hello.asm ~zmatni/public_html/cs64w19/labs/3/Arithmetic.asm ~zmatni/public_html/cs64w19/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.

Task 1: Arithmetic Exercise

You will write an assembly program that will prompt the user for 3 inputs (let's abstractly call them a, b, and c) without a leading string. It will then calculate the value of: 2*(a + b) - 3*c.

You can ONLY use the mult instruction ONCE! (You will lose half the points for this task if you do not follow this rule).

A sample run of this program will look like this, with user input in bold. Please note that when the answer is given, there is NO expectation of a new line:

4
-5
7
-23

You should write your program in the provided Arithmetic.asm template file. You may assume that the user can use signed integers as inputs, but that no multiplication will lead to overflow. You do not actually have to check for that.

Task 2: Hello World

You will write a type of Hello World program that will also get an integer input from the user and print it out. A sample run of this program will look like this, with user input in bold:

Give me an integer number between 0 and 1000:
42
Hello World!
User chose 42. But is it the right answer?!

Your code should be written in the provided hello.asm template file. Be sure that your output matches exactly with the output above. Note where the new lines are and where they are not. (The last line DOES have a new line at the end of it).

Assume that the user will put in an integer between 0 and 1000. You don't have to check for it.

Clues:

Remember what syscall codes you have to use for std input, std output for either integers and strings, and program exit. When printing out strings, remember that you have to first define them under the .data directive.

Test both your programs extensively (we certainly will) before you turn them in!

Turn in Everything Using 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 hello.asm Arithmetic.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.


Copyright 2019, Ziad Matni, CS Dept, UC Santa Barbara. Permission to copy for non-commercial, non-profit, educational purposes granted, provided appropriate credit is given; all other rights reserved.