Fall 2000

Project 4: Simulator

CS61C (Patterson)

Project policy:

You may work in groups of two students(partners don't have to be in the same lab section), But be sure to indicate your partner on your project submission. Project is due Friday, October 20, 2000 at 11:59:59 PM PDT.

Overview and getting started:

In project 3, you created a disassembler for a subset of the MIPS instruction set. 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. Your disassembler did the fetching and decoding, but for this project, instead of printing 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 tough--spim takes in assembly language source files, not ".dump" files, so it performs many of the functions of an assembler in addition to being a simulator.)

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

Project Submission:

Make sure you are in your proj4 directory
type in

submit proj4

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:
  • addu Rdest, Rsrc1, Rsrc2
  • addiu Rdest, Rsrc1, imm
  • subu Rdest, Rsrc1, Rsrc2
  • sll Rdest, Rsrc, shamt
  • srl Rdest, Rsrc, shamt
  • and Rdest, Rsrc1, Rsrc2
  • andi Rdest, Rsrc1, imm
  • or Rdest, Rsrc1, Rsrc2
  • ori Rdest, Rsrc1, imm
  • lui Rdest, imm
  • slt Rdest, Rsrc1, Rsrc2
  • beq Rsrc1, Rsrc2, address
  • bne Rsrc1, Rsrc2, address
  • j address
  • jal address
  • jr Rsrc

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:
  • lw Rdest, offset(Radd)
  • sw Rsrc, offset(Radd)

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 begins by doing the following:

The framework code support several command line options:

Please do not change the framework code.

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.

Submit Project:

The following file is required for successful submission:

Final Remarks:

Programs that run under this simulator also run under spim. However, there are a few rules you need to follow if you'd like to write your own MAL program that run both under this small simulator and under spim: To get your MAL code working correctly with this project, do the following: If your MAL 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. :o)

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.

Feedback:

Please send your comments about the content and the format of project 4 to: cs61c-td@cory.eecs.berkeley.edu

Last updated: 10/06/2000 by cs61c-td