CDA 3103: Computer Organization, Spring 2004
Dr. R. Lent

Homework #2

Due: February 21, 2004. 12:00 PM (noon)

Project Goal

The goal of this programming project is to write a functional simulator for a subset of the MIPS instructions. This project will help you understand how each instruction in the MIPS processor behaves, that is, what the hardware needs to do to execute each instruction. To successfully complete this project, you will need to understand the following items:

  • MIPS Assembly (Project 1)
  • Simple Java programming
  • The precise definition of the MIPS instruction set (lecture sets 2a, 2b, and MIPS reference chart)

    The first project involved writing assembly-language programs. This project involves writing Java code that implements a MIPS processor simulator that can execute machine language programs. You are not required to implement a GUI.

    I have requested Olympus accounts for you, so that you can have immediate access to a Java development environment. However, you are free to use your own computer with your own Java development environment. Let me know if you want to use your Olympus account and I will give you the user and password.

    Part 1: Simulator (80 points)

    In this part, you will write Java code that simulates the fetch, decode, execute cycle of a real computer. In the assignment directory you will find a basic template of the three classes that you have to implement:

  • Memory.java (20 points): Defines class Memory. The constructor receives the size of the memory that we want to use. You will have to implement methods writeByte, writeWord, readByte, and readWord. In addition, this class already defines a method that you can use to load a program into memory. Programs are to be available in a plain text file where each line defines at least two columns (in hexadecimal): the first column represents the memory address and the second, one word representing the instruction (see test.o for an example).

  • RegisterFile.java (20 points): Defines all internal and general purpose registers. The constructor receives the number of desired registers which must be 32. You will have to implement methods to read/write general purpose registers (read, write) and internal registers (readLo, readHi, writeLo, and writeHi). Remember that register 0 must be always zero.

  • mMIPS.java (40 points): Defines the main structure of the simulator. You have to implement here the fetch/decode/execute/update PC cycle of a computer.

    The instructions that you will have to implement are (the MIPS chart will give you a good reference):

  • add, addi
  • sub
  • mult, div
  • mfhi, mflo
  • and, andi
  • or,ori
  • sll, srl
  • lw, sw
  • beq, bne
  • slt, slti
  • j

    Part 2: Testing (20 points)

    In this part, you will write 3 functional tests for your processor simulator. The purpose of these tests is to check that you have correctly implemented individual instructions.

    There are three classes of instructions:

  • arithmetic and logical
  • memory (load and store)
  • control (jumps and branches)

    For each instruction in each class, devise a test case that checks that the instruction is correctly executed. Run these through your simulator and check that instructions are correctly executed.

    Submitting your project

    There are no written reports you have to hand in for this project. As with project 1, submit your files (one zip file) via WebCT before or on the due date. I will not accept late submissions.

    Hints (I may add a few more later)

  • START NOW! You will NEED the time allocated for this project.
  • Assume that you processor is only executing your program and that the program starts at memory address zero (no booting sequence)
  • Don't attempt to implement the entire function before running a single test case. Test each instruction or group of instructions as you implement them. (In other words, don't treat part 1 and part 2 as two independent things.
  • You can debug load and store instructions by looking at the contents of memory.
  • Make sure that your MIPS implementation is big-endian.
  • Use switch statements to decode your instructions. And don't forget the default case.
  • Primitive type int is a 32-bit signed number
  • To compile the program: javac *.java
  • To run the program: java mMIPS name_of_file
  • The java files in the assignment directory are just an example of a possible way to implement the simulator. They may contain errors. You have to understand them and fix/modify them to fit your implementation.