MIPS Simulator in C
The project  involves building a simulated MIPS processor in C. Here are the steps you should folllow:

Step1: Download the simulator
You will notice a bunch of .c and .h files, a Makefile, and a file called ref_cpu created into that directory.


Step 2:  Test run

You should first test to see if the executable ref_cpu works on your machine by typing
./ref_cpu
You should see some output that starts with "Executing a program testing a simple loop", then you should be prompted to input a number and then a string, then see some more output.
From now on, if you ever want to see what your project should actually output, you can run ref_cpu to compare to the output of your code.


Step 3: Test make

The next step is to test to see if the Makefile  configures the compilation of the files correctly. To do this, simply type
make
You should see some output that looks like,
gcc -m32 -o cpu cpu.o r_instructions.o i_instructions.o j_instructions.o syscall.o utilities.o test_programs.o
As you can see, gcc has been invoked. It will generate an executable called cpu. You should test the executable by typing
./cpu
The output should be identical to the output of ref_cpu.
From now on, whenever you want to compile your project, just type
make
Only the .c files that have been changed since the last compilation will be re-compiled. Also, from now on, to execute your compiled project, just type
./cpu


Step 4: Read about MIPS ISA and the project Requirement

You will need to read about the simple MIPS CPU that you will be simulating.
The primary reference will be this description (click on this link).
This takes precedence over any other reference. Implement only the MIPS instructions specified in this document, not in any other reference.

Step 5: Project Parts (5% each)

Part 1:
You will need to implement the MIPS R-instructions (other than syscall) in a file called r_instructions.c. In the r_instructions.h file that I provided you, there is a list of procedures that you have to implement -- each one corresponding to a MIPS R-instruction. As described in the reference materials listed above, each R-instruction procedure (add, addu, sub, etc.) should take as its parameter the full 32-bit instruction and perform the appropriate operation.

Notice that, since each procedure performs the operation of a single instruction (e.g. the add instruction, sll instruction, or the mult instruction, etc.), the procedure does not have to examine the opcode or funct fields of the instruction -- the procedure already knows which instruction is being executed!

If you are having trouble getting started and want to see how I implemented the add instruction, click here. Don't click, though, if you want to figure out for yourself!

To test your implementation of the R-instruction procedures in r_instructions.c, you should simply type
make
to compile your r_instructions.c and link the compiled version (r_instructions.o) with the rest of the provided code. Once it compiles without error, you run the resulting executable by typing
./cpu
When you get the same output as that of ref_cpu, then your code is probably correct (though, of course, you never know!).

If you don't get the same output as that of ref_cpu, and want to figure out which of your instructions has a bug in it, you an take a look at the MIPS instructions that each test program is executing by clicking here. Be sure to read the comments to see what each line of output corresponds to.

Part 2:

Implement the syscall instruction by defining the procedure syscall() in syscall.c . Notice that the syscall() procedure is declared in r_instructions.h . Feel free to put other auxiliary procedures in syscall.c to aid in performing the operations that the syscall instruction requires. Be sure to read the discussion of the syscall instruction in the description of this project above (step 4).

Part 3:

This part of the CPU project is to simulate the I-instructions and J-Instructions of the simple MIPS processor.

You will need to implement the MIPS I-instructions in a file called i_instructions.c. In the i_instructions.h file that I provided you, there is a list of procedures that you have to implement -- each one corresponding to a MIPS I-instruction. As with the R-instructions, each I-instruction should take as its parameter the full 32-bit instruction and perform the appropriate operation.

Notice that, since each procedure performs the operation of a single instruction (e.g. the addi instruction, ori instruction, etc.), the procedure does not have to examine the opcode of the instruction -- the procedure already knows which instruction is being executed!

Remember, just type
make
to compile your code and link the compiled version with the rest of the code. Once it compiles without error, you run the resulting executable by typing
./cpu
When you get the same output as that of ref_cpu, then your code is probably correct.

If you don't get the same output as that of ref_cpu, and want to figure out which of your instructions has a bug in it, you an take a look at the MIPS instructions that each test program is executing by clicking here. Be sure to read the comments to see what each line of output corresponds to.

You will also need to implement the MIPS J-instructions in a file called j_instructions.c. In the j_instructions.h file that I provided you, there is a list of procedures that you have to implement -- each one corresponding to a MIPS J-instruction. As with the instructions you already implemented, each J-instruction should take as its parameter the full 32-bit instruction and perform the appropriate operation.


What to submit:

Email our grader the following 4 files (you do not need to modify any other files in the simulator):
The subject of the email must be: PAC2 Project Submission

The body of the email contains your last name, first name.
GOOD LUCK and ENJOY!