$39
Description
In this project, you will create a simple MIPS simulator. Your simulator will read a binary file containing a MIPS program and execute that program. This will occur in two steps. First, your program will generate the assembly code for the given MIPS program (disassembler). Second, your program will create an instruction-by-instruction simulation of the MIPS program. This simulation will execute instructions sequentially (non-pipelined) and output the contents of all registers and memory (the state of the processor and memory) after each instruction. You will not have to implement exception/interrupt handling
You will be given the expected output for each input program. Your output must exactly match the expected output. The program will be graded simply by using the diff program. The diff program simply lists the dif-ferences between two files. Your output should have no differences with the expected output. We will suppress white space differences, so if you have a space instead of a tab, that is OK.
The command to run diff and suppress white space differences is the follow-ing:
diff -w
Your disassembler can be reused for the next project, so try to write it in a way such that you can separate it from your code to execute the program. In fact, it is easier to write and debug the disassembler first, then write the emulation portion of the project.
Implementation
You may implement this project in any programming language of your choosing. You MUST include instructions in a README file that indicate how to compile (if necessary) and run your program. You MUST include a makefile to compile the code if it is in a language that requires compilation. Examples are linked on the course web site. Your code will be graded on linux on the home server. The only reason it will not be graded there is if you use such an obscure language that home does not have the correct compilers/interpreters for it. C/C++, and Java program must be able to run on home. You may develop locally, then test on home at the end. This program should require NO system libraries, except I/O, so there should be no trouble.
Details
Refer to the MIPS instruction set architecture PDF that is posted along with the course notes on the course website. It provides the details for all MIPS instructions. NOTE that we are making the following changes to the instruction set architecture:
Instead of a 6 bit opcode, we will use a 5 bit opcode that is preceded by a valid bit. The valid bit will be set to 1 if the instruction is valid and should be executed. If the valid bit is set to 0, then the instruction has no effect (it is effectively a NOP). The opcodes will be the same as those in the MIPS instruction set, just ignore the most significant bit (the first bit). We will not change the functionality of any instruction, simply we use this convention for the opcode. The table below illustrates this change:
A suggestion to make coding the program easier. First, read the entire file and simply print if each instruction is valid or not. This will force you to get the general structure of the disassembler in place and debugged before you begin the more complicated step of disassembly.
You will be given an input file containing a sequence of 32 bit instruction words. Assume that the first instruction is at memory address 96. The fi-nal instruction in an instruction sequence is ALWAYS a “BREAK” instruction. Following the break instruction is a sequence of 32 bit 2’s compliment signed integers for the program data. These continue until the end of file.
Your simulator/disassembler must support the following MIPS instructions. Check the MIPS manual for details on instruction representation and operation for each instruction.
J, JR, BEQ, BLTZ
ADD, ADDI, SUB
SW, LW
SLL, SRL
MUL,
AND, OR,
MOVZ
NOP
Input
Your program must accept command line arguments for execution. The follow-ing arguments must be supported (Executable named "mipssim"):
mipssim –i INPUTFILENAME –o OUTPUTFILENAME
Your program will produce 2 output files. One named OUTPUTFILE-NAME_sim.txt, which contains the simulation output, and one named OUT-PUTFILENAME_dis.txt, which contains the disassembled program code for the input MIPS program.
Your program will be graded both with the sample input and output pro-vided to you, and with input and output that is not provided to you. It is recommended you construct your own input programs for testing.
Output
Your program will produce 2 output files.
The disassembled output file should contain one line per word in the input file. It should be separated into 4 columns, each separated by tab character. The columns contain the following information:
The simulation file must have the following format:
Hint: Spend some time creating an output function or class or module or whatever fits your language of choice that handles printing out the various data in this format. Spending a little time to do it right in the beginning will save you a lot of time later. Another hint, the register file and memory can simply be implemented as arrays. Go ahead and make them global variables so you don’t have to pass them around to a bunch of functions. This just makes the code a little more simple to write.
Instructions and arguments should be in capital letters. All integer val-ues should be in decimal. Immediate values should be preceded by a # sign. Be careful and consider which instructions take signed values and which take unsigned values. Be sure to use the correct format depending on the context.
You output will be graded with the diff command. Test your output against the provided sample outputs! Any differences reported by the diff command are assumed to be incorrect output!
Sample files will be provided with the following extensions:
What to Turn In
You may use any programming language you like. If your language of choice is NOT available on the home server, you must demo it to me in my office. The executable must be named "mipssim" once the program is compiled. If your programming language uses an interpreter to execute the program, indicate that in the README file. DO NOT turn in any sample input files or any previously generated output files.
Grading
A valid attempt at the project that compiles and produces some output is worth 70 points. Each produced disassembly and simulation file is worth 5 points. There are 3 bin files from which 3 disassembly files are produced and 3 simulation files.
You will receive 5 points for a produced file if it matches the provided file EXACTLY (with the exception of white space differences).
Programs that do not compile or that do not produce any output will get 0 points. If you do not follow the directions in regards to command line arguments or expected behavior, the penalty is at the discretion of the grader.
Input and Expected Output
The remainder of the document contains PDF versions of the expected output. The input files and text files of the expected output will be available on the course webpage. The final two pages of this document contain programs to con-vert text files containing binary strings to binary files, and vice versa. Use those programs to develop your own MIPS executables for debugging and testing.
Note that your program MUST USE A BINARY FILE AS INPUT. The test1 example contains a text representation of the input file as well as the c version of the program. These are there for informational purposes only. Your program only needs to read the binary file and produce the disassembled file and simulation file.