CS-220, Sections 50, 51
Laboratory Exercise # 1
2-2-06, Report Due Date: 2-9-06

In this lab you will be doing some work with a program that simulates the simple 
computer with a hardwired control unit that we are discussing in class. I will be 
sending the simulator program to the CS-220 listserv and you should save a copy 
of it on the hard disk of the computer you are using in the lab. (If you have 
your own PC, you may want to put the simulator program on that machine as well so 
you can work with it at home. If you do so, please be advised that you will need 
to have the Microsoft .NET Framework installed on your machine. If you have 
Visual Studio .NET installed, the Framework will already be there.) The lab 
instructor will also have a copy of the program executable on a floppy disk, 
Flash drive, or CD-ROM so that if you did not receive the email to the listserv 
you can upload it from the lab instructor's disk.

Description of the Simulator

The simulator simulates execution of programs on the computer described in the 
Week 2 class notes at http://www.cs.binghamton.edu/~reckert/220/hardwire3new.html. 
You should have a copy of those notes with you in lab. When you start the 
simulator, something like the following appears on the screen:


 

Note that there are two windows: one on the left representing the data path section 
of the simple computer and the other one representing its hardwired control unit.

The user may take any of the following actions by pressing the appropriate button in 
the upper right-hand corner of the data path window: Load or change a machine language 
program in the computer's RAM memory, Load a predefined example program into RAM, 
start the clock (in which case the fetch-decode-execute cycle will begin, causing 
whatever program is currently in RAM to be executed until a HLT (opcode 8) instruction 
is fetched and executed), stop the clock, single step through the program (causing the 
next clock pulse to be issued), or reset the registers of the computer to their 
initial values.

Each time a new clock pulse is issued while the clock is running or when the single 
step button is pressed, all of the data path's active control signals are displayed; 
the busses and registers that are currently being used at that moment are highlighted 
in red and their contents displayed; the action that has occurred is indicated; the 
new contents of the registers and memory are displayed; and the appropriate active 
control lines inside the hardwired controller are highlighted in red.

When the user presses the "Load or Change RAM" button, the following dialog box is 
displayed:


 
The address field is preset to 00 and automatically increments by one every time 
the user enters a new value into the "Contents" box. Data are entered into the 
"Contents" box by typing a three digit decimal integer there that can be either a 
machine language instruction or a data value to be stored at the current address in 
RAM. The number is stored in RAM when the user clicks the "Enter Contents" button.  
If the user wants to change the contents of some RAM word other than the one at the 
current address, he or she must enter the desired address into the "Address" box, 
click the "Change Address" button, then enter the desired three-digit number into 
the "Contents" box, and finally click on the "Enter Contents" button. After the 
user is finished entering a series of numbers (e.g., a program), the changes are 
stored in RAM when he or she clicks the "Done" button. The values will be updated 
in the RAM listbox in the data path section. This action also dismisses the dialog 
box. The "Load Memory Dialog Box" may be called up at any time, either to enter a 
new program or to change the current program.


Part 1 -- Using the Simulator with the Example Program

A. Press the "Load Example Program" button. Make a table like the following in 
which you indicate the address and contents of each RAM memory address. For each 
address, on the right-hand side of the table write down an assembly language 
statement that is equivalent to the machine language instruction or pseudo-op 
stored at that address. If there are any jump statements, be sure to make up label 
names and place them at the right place in the assembly language statement. The 
first statement has been done for you:

Machine Language                 Assembly Language 
Address   Contents               Label    Operation   Operand
00        108                             LDA         08


B. Single step the simulator through the program. Make another table that shows the 
active control signals and the contents of all registers after each clock pulse. 
This should be something like the following. (Again the first one has been done for 
you.)

Clock  PC  MAR  MDR  ACC  ALU  NF  B  IR   Ring   Active   RAM Address
Pulse                                      Count  Signals  Being Accessed
0      0    0    0    0    0   0   0  0      0    EP,LM       00
1
2
3
4
5
6
etc.


C. The figure below is a diagram of the simple computer's hard-wired control unit. 
Make 12 copies of this diagram. You are to highlight with a colored highlighter all 
signal lines, AND gates, OR gates, and flip-flops that are active (are high), as well 
as write in the values that are contained in the Instruction Register, the Negative 
Flag, and the "Active Control Signals" boxes in one of these diagrams at each of the 
following moments in the execution of the example program:

Ring Pulse 0 of the first "fetch" of the second instruction in the program
Ring Pulse 2 of the first "fetch" of the third instruction in the program
Ring pulse 5 of the instruction stored at address 00, the first time it is executed
Ring pulse 3 of the instruction stored at address 03, the first time it is executed
Ring pulse 4 of the instruction stored at address 03, the second time it is executed
Ring pulse 5 of the instruction stored at address 04, the first time it is executed
Ring pulse 3 of the instruction stored at address 05, the first time it is executed
Ring pulse 0 of the following fetch
Ring pulse 3 of the instruction stored at address 06, the first time it is executed
Ring pulse 0 of the following fetch
Ring pulse 3 of the instruction stored at address 05, the second time it is executed
Ring pulse 0 of the following fetch

In each case describe exactly what is occurring at that moment in the data path 
section including any changes in the contents of registers, RAM, or the negative flag. 
(For example, for Ring Pulse 0 of the fetch of the first instruction, the answer 
would be something like: "the 0 in the PC is being copied over the bus to the MAR, 
thus accessing the 108 stored at address 00 in RAM".)

 


Part 2. Writing some Programs and Executing them on the Simulator

A. Write an assembly language program targeted for this computer that adds and 
subtracts the numbers stored at RAM addresses 10 and 11, storing the results in 
addresses 12 and 13. Hand assemble (translate) the program into machine language 
and include both the assembly language and the machine language translation (the 
hand-assembled listing) in your lab report. Use the format of the table at the 
beginning of Part 1A of this handout. Enter your program and two data values 
(for example 8 and 3) into the simulator and single step through it. Show a 
working simulator run of your program to the lab instructor. How many clock 
pulses are issued during the program run from the time you start the clock until 
the moment the HLT instruction stops the clock?

B. Write and hand-assemble a program that multiplies two numbers stored in RAM 
using a "multiply by successive additions" algorithm. The numbers to be 
multiplied as well as the result should be stored in successive RAM locations. 
Run your program on the simulator and, when it is working properly, show a 
simulator run to the lab instructor. Use the numbers 5 and 3 (result should be 
15). How many clock pulses are issued during the program run from the time you 
start the clock until the moment the HLT instruction stops the clock? Change the 
numbers to be multiplied and run the simulator again, showing it to the lab 
instructor. Be sure to submit the hand-assembled listing of the program with 
your report.

C. Write and hand-assemble a program that computes the following:

z = (x+y-w)*u/v

Here u, v, w, x, and y will all be variables (memory locations) in the data 
section of your program. The result of the computations should be stored in 
another RAM location called z. You will need to use your "multiply by 
successive additions" algorithm from Part B and create a "divide by successive 
subtractions" algorithm in order to write this program. As in Part B, run the 
program on the simulator and show the run to the lab instructor. Use the 
following data: x=3, y=6, w=5, u=3, v=2. (The result should be 6). How many 
clock pulses does it use to run to completion?  Run it again with other data 
values. Be sure to submit the hand-assembled listing of the program with your 
report.