h4

CS0447 Project 4
Due April 20 (at mid-night)

Write a C++ program that simulates a multicycle CPU which executes a limited set of MIPS instructions, namely lw, sw, add, ori, beq and an exit system call. The input to your simulation will be a machine language program stored in a file "prog.dat". Specifically, your machine should recognize the following opcodes in the high order six bits of an instruction, and simulate the execution of that instruction:

The exit system call should display the content of the 32 machine registers as well as the allocated memory locations (all displayed in hex) before terminating the simulation.

The simulated architecture is a modification of the one shown in Figure 5.33 of your textbook. The components of that architecture and the connections among these components are given in the attached handout. The finite state machine of Figure 5.42 should be slightly modified in accordance with the modifications in the architecture. The modified finite state machines describing the control for the architecture is also given in the attached handout. The control signals corresponding to each state in the finite state machine are as follows (most of the signals have the same meaning as in the textbook):

Your simulation should define an object (class) for each of the major components of the architecture. The public members of each object should be:

While simulating each component, the input to this component should be fetched from the output storage element of the component(s) connected to it in the architecture (in the same way you did in Project 3). To simplify the design, multiplexers are not considered as separate components, but rather as parts of other components.

A class "machine" should be defined to include the five major components of the architecture. Namely, mem_unit, alu, registers, PC_unit and IR_unit. This class has only two public members;

Your main program, will thus look as follows:

INPUT:

The file "prog.dat" should include a sequence of machine language instructions, each instruction being a 32-bit word encoded in hexadecimal. For example

Any character beyond the # sign in a line is a comment and is not loaded into the memory of the machine. Actually, you may assume that prog.dat does not include comments -- only 8 hex symbols per line.

OUTPUT:

The only output is a well formatted display of the registers and memory when an exit system call is encountered.