Laboratory: Data Path and Memory
CSC 105 The Digital Age Spring 2009

Goals:

This laboratory exercise provides practice with the CPU architecture, especially

Part I: CPU Datapath

Exercise 1

  1. Open this page in a new window by right-clicking on the link and choosing "Open Link in New Window" and then come back to this lab. This will bring up the Knob & Switch Datapath Simulator. You should resize your window(s) so that you can see both the simulator and the lab at the same time.

    This simple CPU contains four registers, but no control unit. That is because you will be the control unit! You direct which registers are operated on, and which operations are done.

  2. Take a look at the top box that says "Register Bank." At the right are two command knobs, "A Bus Address" and "B Bus Address." These specify which registers should be read as inputs to the ALU. You can turn each of these knobs one notch by clicking on them. Try that now.
  3. Set the A bus address to R2 and the B bus address to R1 by clicking each appropriately. When a cycle is executed, the CPU will send the values from R2 and R1 along the bus.
  4. The register values are the textboxes with a green background. Currently, the default values of zero are in all the registers. Set the value of R1 to 42 by clicking on the zero and typing in a new value.
  5. Set the value of R2 to be 31.
  6. Now we are almost ready to begin a CPU cycle. First, be sure that the "Animation Speed" is set on "Medium" and "Number Base" is set to "+-10." (Both of these are the default, so if you haven't changed them, you should be in good shape.)
  7. Based on the settings of the bus addresses, what values do you expect to show along the A and B bus? (The text boxes immediately below the two knobs you set.)
  8. Here is what should happen when you click on "Execute" (don't do it yet!) You should see the register values flash and then the arrows connecting the register bank to the "A Bus" and "B Bus" flash. When these flash, click "Halt," which should have appeared in place of "Execute."
  9. Ok, now click "Execute." Are the values along the A and B buses what you expected? (You may click "Halt" once these values appear.)

Exercise 2

  1. Now you have seen how to send data to the ALU. Next we will tell the ALU what to do with the data. Notice that in the bottom right of the simulator is yet another knob entitled "ALU Operation." As you might guess, this knob instructs the ALU what operation to perform on the data it has received. Click the knob so that it points to the instruction "A-B."
  2. There is another box to the left of the ALU knob. This is a diagnostic that reports information on the result of performing the operation you just selected on the input you provided to the ALU. Thus, "zero" has a check next to it because the ALU previously hadn't done anything and its default result was in fact zero. You should see this reflected in the textbox labeled "C:". What do you think will happen when the to the boxes when the result is less than zero?
  3. The current settings settings for your simulator should be for it to run "A-B", where A is R2 and B is R1). With the values of R1=42 and R2=31 that you input earlier, what do you expect the result "C" to be?
  4. Run the simulator to start a cycle with these settings. You should halt the simulator when the result flashes in "C." Is the result what you expected? What happened to the diagnostic boxes? (You may ignore the overflow boxes for now).

Exercise 3

  1. Of course, we want the ALU to do something with the result it has just calculated. This result gets sent along the C bus back into the register bank, where there is one last knob for you to set. The "C Bus Address" knob in the top-left of the simulator indicates where the CPU which register it should store the result of the calculation into. Click the knob to store the result in R3.
  2. Now, run a simulation of a full cycle to subtract R1 from R2 and store the result in R3. You could think of this in terms of your prior programming experience as the statement:
    R3 = R2-R1

Exercise 4

  1. What would happen if you placed the number 15 in R0 and then set all the knobs so that
  2. Use the simulator to verify your prediction.

Exercise 5

  1. What settings (e.g., knob positions) would cause the value stored in R3 to be doubled?
  2. Set R3 to 12 and use the simulator to double that value, using the settings you described above.

Exercise 6

  1. Suppose we want to add the contents of R0, R1, and R2, placing the result in R3. How many cycles will be required? Note that the ALU can only add two things at a time, so you will have to break the problem down into smaller steps.
  2. Write down the settings for each of the cycles to accomplish this task.
  3. Place the values 1, 3, and 5 in R0, R1, and R2, respectively. Use the simulator with the settings you described to add these, placing the resulting sum in R3.
  4. Close the Datapath window.

Part II: CPU and Memory

Exercise 1

  1. In your simulation thus far, we have only been using data from a limited number of CPU registers. Actual computers have much more storage in their main memory. How does the data get from memory into the registers? We need another communication channel (bus). Right-click on this link to open another simulator in a new window. You should see many familiar pieces from Part I, but there are also some new pieces.
  2. Two notable components here are the memory and bus switches. The memory values on the left of the simulator represent RAM. The button next to each memory location indicates which location will be read (R) from or written to (W) in one cycle of the machine.
  3. Notice that the bus connections from the ALU to the register bank now have switches on them. Click these connections to toggle (open and close) the switches.
  4. Open the circuit from the ALU into the C bus, so that there is no longer a connection.
  5. There are also two new connections along the C bus. Remember this is the pathway into the register bank. With memory a part of our machine, we may want to put memory values into registers, rather than ALU results. The connection pointing up from the "Main Memory Bus" into the "C bus" allows us to control this.

    Click to close the connection from the "Main Memory bus" to the "C bus." The connection from the C bus to the memory bus should be open.

  6. Put the value 42 into memory location 0, and select it as the RW location.
  7. Set the connection switch along the "C Bus" into the register bank so that it is closed. Select the "C Bus address" to be R0.
  8. Based on these settings, what do you think will happen when you click "Execute"?
  9. Verify your prediction.
  10. You should have found that the value 42 was copied from memory address 0 and stored in R0. You may have also noted that the ALU was busy working on values that were subsequently ignored. It turns out this is easier than adding circuitry to disable the ALU during a memory read.

Exercise 2

  1. How can we write data to memory? By closing the connection from the C bus to the main memory bus.
  2. Open the switch from memory to the C bus so that nothing is read from memory, then close the switch from the C bus to the memory so that a result can be written to memory.
  3. Set R0=8 and R1=9, and set the A Bus, B Bus, and ALU operation to calculate R0+R1.
  4. Connect the ALU to the C bus by closing the switch that connects them.
  5. Now everything should be set to add our registers and send the output from the C bus along to memory. Set memory location 1 as the destination for the result using the RW button.
  6. Verify this operation by clicking "Execute."
  7. If you have any questions at this point, be sure to ask the instructor or mentor.

Exercise 3

  1. What settings (bus addresses, ALU operation, switches, and memory RW) would result in R0-R3 being stored in memory location 4?
  2. Set R0=23 and R3=16. Using your settings above, verify the desired outcome.

Exercise 4

  1. Change the value of memory location 1 to 28.
  2. What settings would result in the contents of memory location 1 being copied to R2?
  3. Using these settings, verify the desired outcome. Be careful to set all the switches correctly!

For those with Extra Time

Exercise 5

  1. Suppose we wish to add the contents of memory locations 3 and 4 and store the result in memory location 5.
  2. How many cycles would this take?
  3. What are the settings for each cycle?
  4. Set memory location 3 to 13 and memory location 4 to 29 and verify that your settings achieve storing 13+29=42 into memory location 5.
Created: Jerod Weinman, March 16, 2009
Portions adapted from Dave Reed, "A Balanced Introduction to Computer Science," Exercises 14.1-14.6.