Lab 3 – prelab

Introduction to MIPS programming

Update your local gitlab respository to reflect the likely feedback you have from your Lab01. You will likely have to do a git pull to receive this feedback on your previous labs before you can push further changes you make for this lab. Further, if you have made other local changes that are not committed, then you will have to git commit before you can git pull.

In our zyBook, study sections 5.1 to 5.5, inclusively. Then, work out the solutions to the problems below in a nicely organized text file. The file must be named prelab.txt. Make sure to add it in your ~/csci206/Labs/Lab03 git repository and to push it to gitlab before lab. You may have to do a git pull to receive feedback on your previous labs before you can push.

  • [25 points] for the pre-lab assignment
  • [75 points] for the lab assignment

Exercise 1: gdb

Skim through Norm Matloff’s Guide to Faster, Less Frustrating Debugging to answer these questions in your prelab.txt file (all answers can be found in section 4.3 but you are encouraged to read through the whole document):

  1. How do you compile your program so that you get extra debugging information (variable and function names, line numbers, and so on) in gdb?
  2. What is the syntax of the command to set a breakpoint at line 50 that you would type at the gdb prompt?
  3. Assume that your program has an integer called count, that you started the execution of the program in gdb and that it is stopped at a breakpoint: what is the syntax of the gdb command to print the value of count?
  4. Again, assume that your program is stopped at a breakpoint in gdb, what is the syntax of the command to change the value of the integer count to 42?

Exercise 2: MIPS Registers

The MIPS ISA defines 32 registers; in order for the processor to perform arithmetic operations, the operands must all be loaded into registers. All architectures organize registers into groups, according to how instructions use the registers. This grouping is called the procedure call convention (which we will study later) because procedure caller and callee need to agree where to store parameters, temporary data, and return values. For MIPS, these conventions and other useful information are presented in the MIPS reference data, that is, the green sheet at the beginning of the textbook by Patterson & Henessy used by zyBook. (Here is a copy of the nearly identical one from the 4th edition.). You will find what you need for this problem at the bottom right of the front of the green sheet; look for “REGISTER NAME, NUMBER, USE, CALL CONVENTION.”

Section 8.2 in the zyBook describes the procedure call convention in detail. Read the beginning of this section up to but not including the heading Procedure calls. In your prelab.txt file, for each register group, write a few sentences to describe the register or group’s general use and how you might use it. Do not simply copy and paste from the book.

For example, you might start with something like this:

“$zero always contains the constant value zero. This register is useful to extend the capabilities of MIPS instructions that require three arguments. For example, MIPS does not have a move (or copy) command. If we wanted to copy the contents of $s0 to $t0, we could use $zero with the add instruction like this: add $t0, $s0, $zero to achieve the same result as a copy.”

Exercise 3: Simple MIPS instructions

Table 5.2.2 (COD Figure 2.1) lists the basic MIPS instructions. For each of the MIPS instructions below: (a) describe what the instruction does, (b) what the operands to the instruction are, and (c) where the result is stored. Follow the format provided in the example below in your prelab.txt file.

  1. add $s1, $s2, $s3
    (a) Adds the values contained in the two source  registers; stores the result into the destination register. Effectively: $s1 = $s2 + $s3.
    (b) Source Registers: $s2, $s3
    (c) Destination Register: $s1
  2. addi $s1, $s3, 2
  3. lw $t6, 4($s0)
  4. add $t3, $s1, $s2
  5. sub $v0, $t1, $s2

Exercise 4: Working in different bases

We often need to deal with binary values when working in assembly, but writing binary numbers is tiring (all those 1’s and 0’s get old). A much more compact representation is to use octal (base 8) or hexadecimal (base 16). For this reason, we need to master base conversions between decimal, binary, octal, and hexadecimal.

If you need a refresher, let Salman Khan walk you through the process:

Now that you’ve mastered the basics, try to keep up with the binary hand dance (just for fun):

Hopefully, you are now sufficiently warmed up. Perform the conversion of the following numbers from the original base to the indicated base. It is not sufficient to write out the result. You must indicate the intermediate steps in the base conversions to show how you arrived at your final answer. For example, if asked to convert 42 in base 10 to 8-bit binary, you might write: 42 = 32 + 8 + 2 = 2^5 + 2^3 + 2^1 = 00101010.

  1. 59 (base 10) to 8-bit binary
  2. 10111011 (base 2) to 8-bit hexadecimal
  3. 129 (base 10) to 8-bit hexadecimal
  4. 0xFEEDBEEF (base 16) to binary (use as many bits as required)
  5. 0743 (base 8) to binary (use as many bits as required)

When you are done with this assignment, be sure you add your prelab.txt file to your git repo and push to gitlab.


25 points total:

  1. [1 point each, 4 total] Exercise 1: Debugging questions answered correctly.
  2. [2 points each, 12 total] Exercise 2: Answers for the register groups $at, $a0-$a3, $t0-$t9, $s0-$s7, $gp, and $sp.
  3. [1 points each, 4 total] Exercise 3: Each instruction and its effect are described accurately.
  4. [1 point each, 5 total] Exercise 4: Base conversions show intermediate steps and arrive at the correct result.
Print Friendly
Posted in Lab

Leave a Reply

Your email address will not be published. Required fields are marked *


This blog is kept spam free by WP-SpamFree.