MCS-284 Lab 1: Elementary assembly programming

Due October 3, 2013

General expectations

The goal of this lab is to get familiar with the MARS simulator and write and test a couple programs in MIPS assembly language. Because these tasks can readily be accomplished without any nested procedure calls (such as recursion), you won't need to use the stack; that's what the next lab is for.

I expect you to do this lab in teams of two; please form your own team of two. If you are having trouble finding a partner, see me. Include both partners' names when you email me your submission.

Your lab write up can be short and sweet, but it should be English. Specific details I will expect to see are the two programs you are asked to write and information on your testing of each program. The testing information can consist of a careful description of the testing and/or actual test data and results.

Make sure your testing is systematic and thorough. Thorough doesn't mean using large quantities of weird numbers that still only test the same cases; rather, it means using carefully chosen tests to ensure that all cases are covered and all likely bugs exposed, while still allowing the answers to easily be hand-checked.

Be sure to write your program for human readability. That is, use easily understood labels, leave blank lines between blocks of code, and if the higher-level purpose served by a block of instructions is not clear, include an explanatory comment. Also, avoid excessive duplication of code.

If you include a procedure in your program, that procedure should follow the convention regarding what registers it must preserve. The code that calls the procedure should not rely on the values left in other registers. Also, you should use only the standard registers for conveying information into a procedure (arguments in $a registers) or out of a procedure (values in $v registers).

You will do this lab on one of the computers in OHS 326, running OS X. You will use MARS as demonstrated in class. You can click on the Mars.jar icon in the Applications folder; it looks like this:
Mars icon

Be sure that each program exits at the end by putting 10 in register $v0 and then executing a syscall instruction.

Specific Objectives

  1. Do exercise B.6 from page B-82. Your program should terminate with an arithmetic overflow exception if and only if the running sum ever goes outside the range representable as a 32-bit two's-complement signed integer, even if the final sum is representable. This will happen automatically if your program does the addition using the add instruction, doing one addition after each input is read in.

  2. Do exercise B.7 from page B-82. Your program should terminate with an arithmetic overflow exception if and only if the result is outside the range representable as a 32-bit two's-complement signed integer. This will happen automatically if the only addition your program does is to add the two largest numbers and it does this addition using the add instruction. Do not add all three numbers and then subtract off the smallest, since that might fail if the addition of all three causes an overflow but the addition of just the largest two doesn't. However, you may none the less find it useful to think about identifying which one number is the smallest, rather than about identifying which two numbers are the largest.

Common Pitfalls

The most common mistakes students make on this assignment are
  1. Students often assume that registers will have some specific value (e.g., 0) when the program starts running. In fact, the only registers you can count on to have well defined values when your program starts are $sp and $zero. Any other values you observe in MARS are just luck, and shouldn't be counted on.
  2. Students often don't take seriously enough the requirement that testing be thorough, that is, that it probe all cases that differ from one another in some qualitative way. This is a particular problem area with the second program. Think hard about this even before you write a single line of code. How many different cases are there?
  3. Don't forget to review the third paragraph of this assignment which discusses the brief writeup.