MIPS simulator Project 2

1. Overview
MIPS simulator Project 2
The second project is going to be a MIPS simulator. In general, you will be building a program
that simulates the execution of a binary file. There will be several input files of your program,
including a MIPS file that contains MIPS assembly language code, which give you the static data
infomation; a BIN file which contains the corresponding machine code; and a DEBUG file to help
in debugging and grading your program. Further details will be given in the latter part of this
instruction.
1.1 Readings:
Same as Project-1, all of the supplementary materials for this project can be found in Appendix
A, such as the register numbers, instructions, and their machine code format. Moreover, project
2 is based on your first project, fundamental knowledge can be found in the material of
Project-1, such as the MIPS Instruction List.
2. How computer runs the program?
With the idea that all of the codes are stored in memory, and each has an address, we can talk
about how computers run these codes. Long story short, the computer runs the programs
following the machine cycle.
2.1 Machine cycle
A shorter version of a machine cycle looks like this:
1. The computer loads the line of instruction PC is “pointing at”
2. The computer increment PC by 4 (think about why).
3. The computer runs the instruction loaded.
This goes on until the program terminates. PC in this context represents the “program counter”
In other words, PC is the “pointer” the computer maintains that stores the address of the next
instruction to be executed.
3. Project 2 details
3.1 Environment
1. Project 2 should be written in C/C++/Python only.
2. For C/C++ users, you will need to write your own makefile/make, and make sure your
program can execute without a problem on the VM/Docker they provided. You can access
the testing environment through VM instruction on BB.If you would like to write your
program in Visual Studio or other IDE, please test your programs on the virtual machine
CS Help, Email: tutorcs@163.com

3.2.6 Detail specification
• For simplicity, you just need to initialize $fp with the same value as that initialized in $sp, and you can just initialize $gp with the address 32KB above the beginning of the static data section (that is, 0x508000).(for detailed reasons, you may refer to the textbook pages 102- 106 and appendix AS)
• For PC, you should keep PC value to be the first instruction that is not executed yet.(e.g. when you just finish executing the instruction at 0x400004 and dump the register layout out, you should keep PC=0x400008 in your dumped binary file)
• For syscalls 10, 13, 14, 15, 16, 17, you should simulate by directly invoking the Linux APls (some of them have been discussed in tutorial 4) with the parameters given in the “Arguments” column of the system service table in “MIPS Instruction List”.You can just regard syscall 10’s behavior to be a normal exit (with status code 0).
• For syscall 9, you need to simulate the program break in your allocated 6MB memory, and make sure to return a pointer to the location in dynamic data so that we can put stuff in.
• For syscalls 5, 8, 12, you just need to read from .in file one line at a time. For syscalls 1, 4, 11,you can just print the argument in the .out file one line at a time.
• Youdon’tneedtoconsidernegativenumbersfortheseinstructions(divdivumultmultu) and syscall(sbrk).
• Youdon’tneedtoconsideroverflowexceptionininstructionadd.
• For the data types you need to support, you don’t need to consider non-integer numbers(such as float or double) in .word/.byte/.half.
• Allsystemcallshavebeencoveredinthetestcasesreleased,soyoumaychecktoseetheir usages in testing.
• Youcanjustignorethelabelsin.data.
• Tosimplifytheproblem,only.asciiand.asciizuseBig-Endian,and.word.half.byteusethe Little-endian for storage in memory.
Programming Help, Add QQ: 749389476