| CPSC 220 | Introduction to Computer Architecture | Fall 2008 |
In this lab, which is due in two weeks, we will write a simulator for the Larc ISA. A simulator is a software program that acts like a hardware machine. It can run Larc machine code programs, which are just binary programs written using the Larc ISA. There are different types of simulators that one can implement. We will implement what is called a functional simulator or a behavioral simulator. Given a Larc machine program, the simulator will run the Larc program and model the behavior of the Larc machine. In other words, it simulates the behavior of the input/output devices (i.e., the keyboard and monitor) exhibited from running the program on a real Larc machine. The simulator does not have to model the timing of the machine, i.e., how long it takes to run the program on a Larc machine. It also does not have to model the microarchitecture (e.g., ALU, decoder, etc.), but instead, just the components that are exported to the ISA (i.e., to software), which include the program counter (PC), registers, and memory.
You will need to have a good understanding of the Larc ISA in order to complete this lab. Therefore, you will want to make sure that you look over the Larc ISA handout, which was handed out in class. Note: the ISA in the textbook is different from the one we are using so for this assignment make sure you use the handout and not the textbook description of the ISA.
Create a lab05 directory within the ~/cs220 directory that you created in lab 1 for use in this lab. Change to the newly-created lab05 directory. Copy the provided files from the directory /classes/f08/cs220/labs/lab05 to your new lab05 directory. Important: there is also a directory that must be copied to your working directory. Make sure you copy this as well. The following commands should work (note: the "-r" in the cp command allows for copying directories as well as files):
bash$ mkdir ~/cs220/lab05 bash$ cd ~/cs220/lab05 bash$ cp -r /classes/f08/cs220/labs/lab05/* ~/cs220/lab05/
Note: the rest of this lab assumes you are in your lab05 directory.
The four files Simulator.java, ISA.java, TextIO.java, and sim should now have been copied to your lab05 directory. Simulator.java contains the main Java class, which is incomplete and must be completed in this lab. It will eventually contain the code for your Larc simulator. ISA.java contains several auxiliary methods and variables that can be used to find various characteristics of the Larc ISA (e.g., width of the machine, the opcode for an add instruction). You may find these methods and variables useful when writing your simulator code in Simulator.java. As always, TextIO.java defines some methods for reading data typed by the user into your program. Note: it must reside in the same directory as the programs that use it, so make sure it was actually copied to the lab05 directory. Finally, the file sim is a working simulator, which you can use when debugging your own simulator.
In addition, the directory tests also should have been copied to your working directory. This directory contains several test programs, which you can use to debug your simulator. Each test program is a file containing Larc machine code, which your simulator should eventually be able to run correctly. Test programs have a ".out" extension. For example, there is a test program called nim.out for playing the game Nim. Once your simulator is working, you can run the program in your simulator with the command: java Simulator tests/nim.out. To run the Nim Larc machine code program in a working simulator (i.e., sim), you can use this command: ./sim tests/nim.out.
There is one exercise for this week's lab. It is due in two weeks, not one week, at the start of lab on 10/23. Remember to use good programming style as laid out in lab 1.
In this exercise, you will write a functional simulator for the Larc ISA. Your simulator should take as input a Larc machine program, which is a text file containing lines of 0s and 1s (16 per line), and run that program. Your simulator does not have to model the timing of a Larc processor, i.e., how long it takes to run a program. But it does need to simulate the behavior of a Larc processor, i.e., the input/output (keyboard events, monitor events) when running a particular Larc program. Unlike in the ALU program from lab 3, there are no constraints on the language constructs that you can and cannot use (if statements, while loops, etc.). However, you must use only the provided classes with four exceptions: you may use Math, String, Vector, or Hashtable (note: you will not necessarily need all four of these, but they are available if you want to use them). See the Java class descriptions for more details on these classes.
For a complete description of the Larc ISA read this handout. Before starting this assignment you should look over this handout. You are responsible for implementing a simulator which follows the specifications laid out in the handout. In your simulator, you will need to model the three main components of the Larc ISA: the program counter (PC), memory, and registers. You can use whatever kinds of variables you find convenient for implementing these structures so long as they are within the requirements specified above (i.e., an array, String, Vector, Hashtable, or a data structure defined by you). You will also need to be able to decode instructions. Given 16 0s and 1s (a word in memory), you will need code that determines what instruction that refers to. In addition, your code will also need to correctly execute an instruction, once decoded. This may require updating some of your architectural structures such as the PC, registers, and memory. Your simulator will follow the fetch-and-execute cycle, continuing to fetch, decode, and execute instructions until an exit system call is executed by the machine program.
Your working directory should contain four files and one directory, which were copied from commands described above. The files include Simulator.java, ISA.java, TextIO.java, and sim. Simulator.java contains skeleton code for the simulator program. You will complete this code in this exercise. ISA.java contains several variables and methods that you may find useful when implementing your simulator. As usual, the file TextIO.java contains code for reading input from the command-line. The file sim contains a working simulator, which you can use to determine when your simulator is working correctly. The directory tests contains some test programs, which you can use to debug your simulator. Each test program has the ".out" extension. For example, there is a test program called nim.out. You could run this in your simulator with the command: java Simulator tests/nim.out. You can also run the test program in the working simulator with the command: ./sim tests/nim.out. When your simulator is working, it will produce the same output as sim. Note: you may want to write additional test programs to test your simulator.
As in other assignments, you are expected to document your program. You should have comments describing all methods, variables, and non-obvious statements. This will be part of your grade on this exercise. In addition, you must answer the following questions, which you can put in a comment at the top of your program:
Verify that your lab05 folder contains all of the files you created or modified for this lab (which is just Simulator.java in this case), then copy your entire lab05 folder to the handin directory ~mcorliss/handin/cs220/username (where username is replaced with your username). For example, if your working directory is ~/cs220/lab05/ then you could do the following:
cp -r ~/cs220/lab05 ~mcorliss/handin/cs220/username
where username is replaced with your particular username (e.g., mcorliss).