In this project, you will create an instruction interpreter for a subset of MIPS code. Starting with the assembled instructions in memory, you will fetch, disassemble, decode, and execute MIPS machine instructions, simulating each stage in the computation. Youre creating what is effectively a miniature version of MARS! There is one important difference, thoughMARS takes in assembly language source Hiles, not .dump Hiles, so it contains an assembler, too. You may work with a partner for this project. Each person will turn in the following for the project on CatCourses: Completed computer.c Testing.txt/doc which outlines your testing strategy All the *.s and *.dump Hiles you used to test your project in test.tgz Name of your partner in the submission box.Project Speci,icationThe Hiles sim.c, computer.h, and computer.c comprise a framework for a MIPS simulator. Complete the program by adding code to computer.c. Your simulator must be able to simulate the machine code versions of the following MIPS machine instructions:addu Rdest, Rsrc1, Rsrc2addiu Rdest, Rsrc1, immsubu Rdest, Rsrc1, Rsrc2sll Rdest, Rsrc, shamtsrl Rdest, Rsrc, shamtand Rdest, Rsrc1, Rsrc2andi Rdest, Rsrc, immor Rdest, Rsrc1, Rsrc2ori Rdest, Rsrc, immlui Rdest, immslt Rdest, Rsrc1, Rsrc2beq Rsrc1, Rsrc2, raddrbne Rsrc1, Rsrc2, raddrj addressjal addressjr Rsrclw Rdest, offset (Radd)sw Rsrc, offset (Radd)Refer to the handout attached in the assignment page which contains the binary code of the MIPS instructions. Once complete, your solution program will be able to simulate real programs that do just about anything that can be done on a real MIPS, with the notable exceptions of Hloating-point math and interrupts.The framework code1. It reads the machine code into memory, starting at address 0x00400000. (Inkeeping with the MARS convention, addresses from 0x0000000 to 0x00400000are unused.) We assume that the program will be no more than 1024 words long.The name of the Hile that contains the code is given as a command-line argument.2. It initializes the stack pointer to 0x00404000, it initializes all other registers to0x00000000, and it initializes the program counter to 0x00400000.3. It provides simulated data memory starting at address 0x00401000 and ending ataddress 0x00404000. Internally, it stores instructions together with data in thesame memory array.4. It sets Hlags that govern how the program interacts with the user.It then enters a loop that repeatedly fetches and executes instructions, printing informationas it goes: the machine instruction being executed, along with its address and disassembled form (to be supplied by your PrintInstruction function); the new value of the program counter; information about the current state of the registers; information about the contents of memory.The framework code supports several command line options:ImplementAs discussed in lecture, Fetch, Decode, Execute, Mem, and RegWrite are the Hive processing stages of the MIPS archetecture. In our simulator, these steps involve completing the following tasks. The Fetch step has been implemented for you so you job is to Hill in the remaining functions: Decode Given an instruction, Hill out the corresponding information in aDecodedInstr struct. Perform register reads and Hill the RegVals struct. Theaddr_or_immed Hield of the IRegs struct should contain the properly extended versionof the 16 bits of the immediate Hield. Execute Perform any ALU computation associated with the instruction, and returnthe value. For a lw instruction, for example, this would involve computing the base +the offset address. For this project, branch comparisons also occur in this stage. Mem Perform any memory reads or writes associated with the instruction. Notethat as in the Fetch function, we map the MIPS address 0x00400000 to index 0 inour internal memory array, MIPS address 0x00400004 to index 1, and so forth. Ifan instruction accesses an invalid memory address (outside of our data memoryrange, 0x00401000 0x00403fff, or not word aligned for lw or sw), your codemust print the message, Memory Access Exception at [PC val]: address [address],where [PC val] is the current PC, and [address] is the offending address, both printedin hex (with leading 0x). Then you must call exit(0). RegWrite Perform any register writes needed.-iruns the program in interactive mode. In this mode, the program prints a >prompt and waits for you to type a return before simulating each instruction. Ifyou type a q (for quit) followed by a return, the program exits. If this optionisnt specified, the only way to terminate the program is to have it simulate aninstruction thats not one of those listed on the previous page.-rprints all registers after the execution of an instruction. If this option isntspecified, only the register that was affected by the instruction should be printed;for instructions which dont write to any registers, the framework code prints amessage saying that no registers were affected. (Your code needs to signal whena simulated instruction doesnt affect any registers by returning an appropriatevalue in the changedReg argument to RegWrite.)-mprints all data memory locations that contain nonzero values after the executionof an instruction. If this option isnt specified, only the memory location that wasaffected by the instruction should be printed; for any instruction that doesntwrite to memory, the framework code prints a message saying that no memorylocations were affected. (Your code needs to signal when a simulated instructiondoesnt affect memory by returning an appropriate value in the changedMemargument to Mem.)-d is a debugging flag that you might find useful.In the case of an unsupported instruction, make sure that you call exit(0) somewherein your code, before PrintInfo and fetching the next instruction. Do not print anyspecial error message in this case..In the UpdatePC function, you should perform the PC update associated with the currentinstruction. For most instructions, this corresponds with an increment of 4 (which we havealready added).The PrintInstruction function prints the current instruction and its operands in text.Here are the details on the output format and sample.output Hile contains the expectedoutput for sample.dump: The disassembled instruction must have the instruction name followed by a tabcharacter (In C, this character is t), followed by a comma-and-space separated listof the operations. For addiu, srl, sll, lw and sw, the immediate value must be printed as a decimal number(with the negative sign, if required) with no leading zeroes unless the value isexactly zero (printed as 0). For andi, ori, and lui, the immediate must be printed in hex, with a leading 0x and noleading zeroes unless the value is exactly zero (which is printed as 0x0). For the branch and jump instructions (except for jr), the target must be printed as afull 8-digit hex number, even if it has leading zeroes. (Note the difference betweenthis format and the branch and jump assembly language instructions that youwrite.) Finally, the target of the branch or jump should be printed as an absoluteaddress, rather than being PC relative. All hex values must use lower-case letters and have the leading 0x. Instruction arguments must be separated by a comma followed by a single space. Registers must be identiHied by number, with no leading zeroes (e.g. $10 and $3) andnot by name (e.g. $t2). Terminate your output from the PrintInstruction function with a newline. As an example, for a store-byte instruction you might return sbt$10, -4($21)
.Here are examples of good instructions printed by PrintInstruction:addiu $1, $0, -2lw $1, 8($3)srl $6, $7, 3ori $1, $1, 0x1234lui $10, 0x5678j 0x0040002cbne $3, $4, 0x00400044jr $31Here are examples of bad instructions:# shouldnt print hex for addiuaddiu $1, $0, 0xffffffff# shouldnt print hex for swsw $1, 0x8($3)# should use reg numbers instead of namessll $a1, $a0, 3# no spaces between argumentssrl $6,$7,3# forgot commasori $1 $1 0x1234# hex should be lowercase and not zero extendedlui $t0, 0x0000ABCD# address should be in hexj 54345# forgot the leading 0xjal 00400548# needs full target address in hexbne $3, $4, 4The Hiles sample.s and sample.output provide an example output that you may usefor a sanity check. We do not include any other test input Hiles for this project. You mustwrite the test cases in MIPS, use MARS to assemble them, and then dump the binary code.You will need to submit everything you used to test your project.MARS places anything that follows the .data assembler directive sequentially in memory.However, this will not be reHlected in the binary Hile that MARS dumps. That dump Hile onlycontains instructions. Therefore, instead of depending on MARS to load data memory foryou, you should use instructions. For example, suppose you want to write a MIPS programthat uses an array of 5 words called foo which is initialized with the integers 1, , 5.Normally, you would write something like:.datafoo: .word 1,2,3,4,5For this project, you would not use the .data section. Instead you would have your programinitialize the array:__start:lui $t0, 0x1001ori $t0, 0x0000addiu $t1, 1sw $t1, 0($t0)addiu $t1, 2sw $t1, 4($t0)addiu $t1, 3sw $t1, 8($t0)addiu $t1, 4sw $t1, 12($t0)addiu $t1, 5sw $t1, 16($t0)You could also do this in a loop. This may seem a bit tedious and time consuming but itgreatly simpliHies the simulator.
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.