Write an assembly program that simulates a subset of the MIPS-I ISA. Your program will be called by a shell that establishes the environment and will execute until it does a return back to the shell. The shell for the program can be found here. You can also copy the shell from /usr/class/ee182/WWW/Projects/PA2/simulator.s. Please add your code DIRECTLY to the shell (where specified). Once you have completed the assignment, follow the submit directions to submit your program electronically. DO NOT turn in paper copies of your code.
The Subset
Your emulator should interpret the following MIPS instructions:
The Environment
Your routine will be called by our shell routine. The shell allocates memory,
loads in a program, and passes you the following values:
As usual, $ra will have the return address. Execution halts on the simulator's (jr) to the address in $ra. The simulator procedure should return these values:
In addition, after you have completed simulation of the program, but before you return (via "jr $ra"), print out the following statistics:
For example, if your simulator executes 100 instructions, and if 57 are R-type, 32 are I-type, and 11 are J-type ... your code should print out the following:
R-type: 57
I-type: 32
J-type: 11
For our grading convenience, we are asking you to print out your statistics in this prescribed format and only in this prescribed format! You MUST print out your statistics in the above format! Be sure to place a carriage return at the end of each line.
Programs for your Simulator
Programs for your simulator consist of integer values, one per line, that
represent hand-assembled MIPS instructions. The end of the program is signified
by a 0. The shell that we give you will read in a file line-by-line, storing it
into the "code" space, stopping when it reads in a 0. The 0 will also
be stored in the code space so that your simulator knows where it should stop
execution. The command-line used to execute a program is as follows:
spim -file simulator.s < myprogram
where "simulator.s" is your assembly language code implementing the MIPS simulator (shell plus your code) and "myprogram" is a text file containing integers representing MIPS instructions. The "<" symbol redirects input so that spim takes its input from the file "myprogram" rather than from the console.
Testing
We provide you with some test sequences here, but we recommend that you also
create your own test sequences. While the programming is to be done
individually, we encourage the group creation and sharing of test code. You
will need to hand compile your test code to generate a file of integers that
can be read in by the shell.
The test code can also be copied from
/usr/class/ee182/WWW/Projects/PA2/.
If you choose to write your own code the script spimulator.pl (written by Eric
Silverberg, an EE182 from a previous quarter) might be useful. To run it, type
spimulator.pl at the command line and follow the directions, you will need a
file containing an assembly language program. PLEASE do not contact Eric
Silverberg if you have problems with this script, since he is letting us use it
as a favor, so please direct any questions to the TAs. Please also note that
since the program was not written by the course staff it is
"unsupported" and may have bugs.
This assignment is intended to facilitate your understanding of how MIPS instructions are decoded and executed.
The first part of the assignment is to implement the addi instruction. Your simulator should be able to run programs that contain only addi instructions, similar to the addi sample program provided. The output should include the instruction count for all three instruction types, though both R and J instruction counts will be 0.
This portion of the assignment is due on Wednesday, 11/13/02 by 11:59 PM. The goal is to get you started on the project early since this assignment is considerably more involved than the previous programming assignment.
Good luck!