Computer Science 2500
Computer Organization

Rensselaer Polytechnic Institute
Spring 2009


Lab 2: Decoding MIPS Instructions
Due: 11:59 PM, Tuesday, February 3, 2009


As you have seen in class and in the readings from Patterson and Hennessy, MIPS machine instructions are encoded as 32-bit values. Each 32-bit value representing an instruction is viewed as a collection of fields that determine the instruction's operation and its operands. Your task for this week's lab assignment is to implement a MIPS instruction decoder in C. You are to work individually for this lab assignment.

Your program should read in MIPS instructions as hexadecimal numbers from standard input. Each instruction (which you should read into an unsigned int) is then to be passed to a function that will parse the instruction bit fields and return a structure that contains these values in a more convenient format. It should then call another function that prints out the values of the fields.

Getting Started

A starter framework for this lab assignment can be found on the CS Lab Unix systems in

/cs/terescoj/shared/cs2500/labs/mipsdecode/mipsdecode.tar.gz

Copy that file to your account, extract it to an appropriate work area. This is a "gzipped tar file". To extract it, you should be able to issue the command

tar xvfz mipsdecode.tar.gz

This will create a new directory mipsdecode in your current directory. When you change to that directory, you should find five files:

Your task is to fill in the missing implementations of the functions parseMipsInstruction and dumpMipsInstruction in mipsInstruction.c, and main in driver.c.

My Implementation

I have provided .o files that you can link with on a CSLab FreeBSD system to try out my implementations of driver.c and/or mipsInstruction.c. See the Makefile for details. Your program's behavior should be identical to that of mine when you have completed the assignment.

To use my implementations, you should log into a FreeBSD system. You can do so by a secure shell login to freebsd.remote.cs.rpi.edu.

Main Tasks

Your main tasks to complete this lab:

  1. Develop the main input loop in main().
  2. Write parseMipsInstruction().
  3. Write dumpMipsInstruction().

Your code should compile with no warnings when using the -Wall flag to gcc (as is used by the provided Makefile). You should be careful to free any allocated memory at an appropriate time.

We will test your program on a larger input set than that provided in the instructions file. It is up to you to make sure you test all cases that may not be covered in that file. Your program will be graded on style, correctness, and documentation.

What To Turn In

Submit a single tar file called lab2.tar that will extract its contents into a directory mipsdecode. The tar file should include four files: Makefile, driver.c, mipsInstruction.h, and mipsInstruction.c. Make sure your name is in the C files that you modified. Please do not include any additional files, such as emacs backup files, object files, or your executable. When your tar file is ready to go, you may submit it from any CSLab Unix system with the command:

submit comporg lab2 lab2.tar