Department of Electrical and Computer Engineering
The University of Texas at Austin

EE 360N, Spring 2001
Y. N. Patt, Instructor
Kameswar Subramaniam, Onur Mutlu, TAs
Lab Assignment 2; Due February 18, 11.59pm.


For this assignment, you will write a simulator for the LC-2. The simulator will take two input files:

1. A file entitled ucode which holds the microcontrol store.

2. A file entitled isaprogram holding an assembled LC-2 program.

The simulator will execute the input LC-2 program, using the microcode to direct the simulation of the microsequencer, datapath, and memory components of the LC-2.

Note: The file isaprogram is the output you generated in Lab Assignment 1. This file should consist of 4 hex characters per line only. Each line of 4 hex characters should be prefixed with '0x'. For example, the instruction NOT R1, R6 would have been assembled to 1001001110111111. This instruction would be represented in the isaprogram file as 0x93BF. The file ucode should consist of 64 rows and 31 columns of zeros and ones.

The simulator is partitioned into two main sections, the shell, which allows a user to control the simulator, and the simulation routines, which carry out the simulation.

The Shell

The purpose of the shell is to provide the user with commands to control the execution of the simulator. 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:

1. go - simulate the program until a HALT instruction is executed

2. run n - simulate the execution of the machine for n cycles

3. mdump low high - dump the contents of memory, from location low to location high to the dump file

4. rdump - dump the current cycle count, the contents of registers , IR, PC, MAR, MDR, and other status information to the dump file

5. ? - print out a list of all shell commands

6. quit - quit the shell

The Simulation Routines

The simulation routines carry out the cycle-by-cycle simulation of the input LC-2 program. The simulation of any cycle is based on the contents of the microinstruction register. The simulation consists of two concurrently executing phases:

The microsequencer phase uses 9 bits from the microinstruction register and appropriate literals from the datapath to determine the address of the next microinstruction.

The datapath phase uses 22 bits of the microinstruction to manipulate the data in the datapath. Each microinstruction must be literally interpreted. For example, if the GATEMDR bit is asserted, then data must go from the MDR onto the bus. You must also establish an order for events to occur during a machine cycle. For example, data should be gated onto the bus first, and later loaded into a register.

Note that 2 bits of the microinstruction determine the operation of memory. We will assume a memory operation takes five cycles to complete. That is, the ready bit is asserted sometime at the end of the fourth cycle.

Since the two phases occur concurrently, care must be taken to prevent unwanted effects. For example, the microsequencer phase generates a new microinstruction but that instruction is not available until the next cycle. If we perform this phase before the datapath phase, then the datapath will execute the wrong microinstruction. To prevent this, you should save the current state of the microinstruction and switch to the new microinstruction at the end of all three phases.

What To Do

The shell has been written for you. From your ECE LRC account, copy the following file to your work directory:
At present, the shell reads in the microcode and input program and initializes the machine. It is your responsibility to write the correct microcode file and to augment the shell with the simulation routines that simulate the activity of the LC-2. In particular, you will be writing the code to perform the activities of the three phases (datapath, microsequencer, memory) described above.

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 correct microarchitecture structures sample the correct signals.

What To Turn In

You will submit your lab assignment electronically. Instructions will be posted on the course web page on how to do so. You will submit the following:

  1. Adequately documented source code of your simulation routines.
  2. Your microcode file.
  3. Simulate the LC-2 assembly program that you wrote and assembled for Lab Assignment 1. Run the program three times, using a different input value each time. Dump the memory contents of location 0x4001 before and after each run. Turn in a copy of the dump file. (Instructions will be posted on the course web page)

Handouts You Need to Use

Your simulator needs to simulate the following microarchitecture implementation of the LC-2 ISA:

These figures are different from what you have in your Appendix C handout. So please download and use them for this lab assignment.