In this assignment, you will implement a simple one-wide in-order 5 stage pipeline trace driven simulator. We provide a simulator frame to help your assignment. Your job is to complete the simulator to simulate the following architecture. Introduction
For this assignment, you will write an instruction-level simulator for the LC-3b. The simulator will take one input file entitled isaprogram, which is an assembled LC-3b program. The simulator will execute the input LC-3b program, one instruction at a time, modifying the architectural state of the LC-3b after each instruction.
Note: The file isaprogram is the output file from the assembler.linux. This file should consist of 4 hex characters per line. Each line of 4 hex characters should be prefixed with '0x'. For example, the instruction NOT R1, R6 is assembled to 1001001110111111. This instruction would be represented in the isaprogram file as 0x93BF.
The simulator is partitioned into two main sections: the shell and the simulation routines. We are providing you with the shell. Your job is to write the simulation routines.
The Shell
The purpose of the shell is to provide the user with commands to control the execution of the simulator. The shell accepts one or more ISA programs as arguments and loads them into the memory image. In order to extract information from the simulator, a file named dumpsim will be created to hold information requested from the simulator. The shell supports the following commands:
The simulation routines carry out the instruction-level simulation of the
input LC-3b program. During the execution of an instruction, the
simulator should take the current architectural state
and modify it according to the ISA description
of the instruction in Appendix A. The
architectural state includes the PC, the general purpose registers, the condition
codes and the memory image. The state is modeled by the following C code:
#define WORDS_IN_MEM 0x08000 #define LC_3b_REGS 8 typedef struct System_Latches_Struct{ int PC, /* program counter */ N, /* n condition bit */ Z, /* z condition bit */ P; /* p condition bit */ int REGS[LC_3b_REGS]; /* register file. */ } System_Latches; int MEMORY[WORDS_IN_MEM][2];The shell code we provide includes the skeleton of a function named process_instruction, which is called by the shell to simulate the next instruction. You have to write the code for process_instruction to simulate the execution of instructions. You can also write additional functions to make the simulation modular.
What To Do
The shell has been written for you. From your CoC account, copy the following file to your work directory:
lc3bsim2.cAt present, the shell reads in the input program and initializes the machine state. It is your responsibility to complete the simulation routines that simulate the instruction execution of the LC-3b.
Add your code to the end of the shell code. Do not modify the shell code.
The accuracy of your simulator is your main priority. Specifically, make sure the architectural state is correctly updated after the execution of each instruction.
It is your responsibility to verify that your simulator is working correctly. You should write one or more programs using all of the LC-3b instructions and execute them one instruction at a time (run 1). You can use the rdump command to verify that the state of the machine is updated correctly after the execution of each instruction.
Since we will be evaluating your code on linux, you must be sure that your code compiles on one of the CoC linux machines (helsinki.cc.gatech.edu) using gcc with the -ansi flag. This means that you need to write your code in C such that it conforms to the ANSI C standard. You should also make sure that your code runs correctly on one of the CoC linux machines.
Please submit your lab assignment electronically at T-square. You will submit only the lc3bsim2.c file with adequately documented source code of your simulation routines.
Important
TEMP = PC†
if (bit(11)==0)
PC = BaseR;
else
PC = PC† + LSHF(SEXT(PCoffset11), 1);
R7 = TEMP;
* PC†: incremented PC