CSE/EEE 230 Project 3
Due March 29th, 2011. 11:59 pm
This Project is one of a few continued projects to write an emulator for the MIPS machine.
[The project can be written in C or C++ or Java]
You are to write a program that emulates a MIPS machine. It reads a MIPS binary program from a file and then runs the program as if a real MIPS CPU ran the program.
The MIPS binary file is written as a file with hexadecimal numbers (in ASCII). For example the following assembly language program when fed into the assembler:
main: # program starts here
li $t0, 25
li $t1, 30
li $t2, 35
add $t0, $t0, $t1
add $t0, $t0, $t2
move $a0, $t0 # sum of 25, 30 and 35 in $a0
The above, gets converted by the assembler to: (note, pseudo instructions have been eliminated)
addiu $8, $0, 0x19
addiu $9, $0, 0x1e
addiu $10, $0, 0x23
add $8, $8, $9
add $8, $8, $10
addu $4, $0, $8
Then the assembler loads the following hexadecimal binary at location 0x00400000
In this project, your program will get as input a file containing the above set of numbers (or some other number sequence, in ASCII charaters, representing hexadecimal values). You will place this number sequence into an array that will hold the MIPS program. This array will be assumed to be “instruction memory” and will supposedly start at memory location 0x00400000.
You will have a PC initialized to 0x00400000. After loading the program, you are to execute the program. This is done by decoding the opcode (and if needed the “func” part), obtaining the register addresses and any other data in the instruction. Then do what the instruction does. You will need to have a register file, consisting of another array of 32 registers.
To make this part simple, you are to assume that the MIPS assembly language is restricted to the following instructions:
ADD, ADDU, ADDI, ADDIU, SUB, SUBU
BEQ, BNE, J
(please note that BEQ uses 16 bits of the immediate as bits 17-2 of destination address and J uses 26 bits of the immediate for bits 27-2 of destination address)
SW, LW [do not implement yet]
….and more will be added (e.g. JAL, JR, ORI and such).
For this part, there is no “data” section. It will be added later.
For debugging and control purposed we will extend the MIPS binary language. We provide two special instructions:
FFFFFFFF -- print all registers
This will print all the registers in some human readable fashion. That is, anywhere in the program we can place an FFFFFFFF code that prints all registers.
FFFFFFF0 – stop execution of program
To begin with, you may use the above code sample provided to test your emulator. You should also write some programs and test them. Getting binary code from MARS is easy, write the code in assembly and then use File->Dump Memory. Choose .text and Hexadecimal Text and then click “Dump to File”
Place your emulator files into a folder. Comment your code well and include your name and email in each source file. Also place the binary program files of any programs you have tested the emulator on, into files name test1.t, test2.t and so on. ZIP all files into one file and send it to teaching assistant’s email. Please keep the following file naming rules.
Zip file: LastName_FirstName_ASUID.zip
Only last submission will be graded if multiple submissions are found.
Late submission is rarely accepted, and may carry penalties.
works on your test cases: 60%
Your emulator works on other test cases, we create: 40%