Machine Structures. Fall 2003, UC Berkeley
Project 3: MIPS Instruction Simulator

Overview and getting started:

In this project, you will create an instruction simulator for a subset of the MIPS instruction set. Your simulator will fetch, decode, and execute MIPS machine instructions. As well as printing the assembly language version of the instructions, you will perform the actual operation (indicated by the instructions) on the machine state. You are creating what is effectively a miniature version of spim! There is one important difference though--spim takes in assembly language source files, so it performs many of the functions of an assembler in addition to being a simulator. Your simulator will take binary input, generated from spim's dump command.

You should make a directory in your home directory named proj3, and copy all the files from ~cs61c/lib/proj3 into your proj3 directory. Run make to compile your project. It will create sim for you.

Project Submission:

Make sure you are in your proj3 directory and run

submit proj3

You only need to submit the computer.c file.

Assignment:

Part 1: regular instructions The files sim.c, computer.h, and computer.c comprise the framework for a MIPS simulator. Complete the program by filling in appropriate procedures in computer.c. It should be the only file you modify. Your simulator must be able to simulate the machine code version of the following MIPS instructions:

Part 1 does not involve instructions that access memory (loads and stores); all computations are done in the registers.

Part 2: memory access

Add support for two more instructions:

With these additions, the program can simulate real programs that do just about anything that can be done on a real MIPS processor (with the notable exceptions of floating-point math and interrupts).

How does the code work?

The framework code already does the following:

The framework code support several command line options:

All the printing in the framework code is done in the PrintInfo function. You will need to supply a Disassemble function that will also do some printing.

Do not change the framework code or add any more source files. All your code should go in the empty functions that need filling in or in additional functions called by your code.

Disassembly:

The Disassemble function is called by the simulator to print the assembly language version of each instruction. You will need to supply this function. Your output for each instruction should be in exactly this form:
instr   arg1, arg2, arg3
with a tab between the instruction name and the first argument and a comma and space between subsequent arguments.

The instruction name is the standard mnemonic as listed on pages A-54 to A-75. The arguments are register numbers or immediate values. A register operand of an instruction should be written with a dollar sign and a number, for instance $2, not $v0.

Immediates should be in signed decimal, except for in these cases:

Some instructions do not have all three arguments. Output them with one or two arguments just as spim would write them.

Here is example disassembly output for a three instruction sequence starting at address 00400000 and containing a two-instruction loop (your actual simulator output will contain more information per instruction than shown below):

ori   $5, $5, 0x00ff
addi  $5, $5, -1
beq   $5,$0,0x00400004

Testing:

We have provided two tests for you: test1 includes most of the instructions you need to implement for part 1; test2 includes some of those instructions, plus the memory access instructions. For each test (test1 and test2) there are actually three files: testN.s, which is the assembly code; testN.dump, which is the binary code your simulator will take as input; and testN.out, which is the correct output for your simulator. You can run the tests separately by typing make test1 or make test2. When you are fairly certain everything works, you can run them consecutively by typing make test.

The test files do not include all the instructions you need to implement, and this is done on purpose. You should be able to easily create your own test files (by writing .s files and dumping them using spim) and test your code thoroughly.

Final Remarks:

Programs that run under this simulator also run under spim. However, there are a few rules you need to follow as you write your own programs that run both under this small simulator and under spim: To get your assembly code working correctly with this project, do the following: If your MIPS code runs under spim but not in your simulator, it either means you did not follow the above rules or your simulator has a bug in it, or both.

REMEMBER: the grading will be done almost entirely by automated scripts. Your output must exactly match the specification, which makes correctness the primary goal of this project. Make sure you know exactly how to output all kinds of instructions.





This page last modified 10/12/2003, by J. Wawrzynek. using emacs.