Computer Science 324
Computer Architecture

Mount Holyoke College
Fall 2009


Lab 5: Decoding MIPS Instructions
Due: 1:15 PM, Friday, Nopvember 6, 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 Linux systems (or remotely on babyred.cs.mtholyoke.edu) in

/home/jteresco/shared/cs324/labs/mipsdecode/mipsdecode.tar.gz

Copy that file to your account, extract it to an appropriate work area, and change to that directory. 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 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.


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.


Grading

I 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.

The lab will be graded out of 30 points. 20 points will be awarded for correctness, 4 for efficiency, and 6 for style and documentation. The efficiency portion of the grade may be impacted, for example, if you use unnecessarily complex functions or operations to break down the input number into fields. Good style requires appropriate code formatting and meaningfule variable and function naming. A well-documented submission will include a comment in each file describing the contents of the file, a comment with each function describing what it does, what parameters it expects, and any restrictions on its usage, and comments clarifying any potentially confusing code segments.


What To Turn In

Submit a single tar file called mipsdecode.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.