COMP 131

The ALU and Memory


Reading Assignments

How Computers Work


Related Web Sites

The Basic Knob & Switch Computer
A model of a simple CPU with 4 registers and an ALU (with operations for addition, subtraction, bitwise-AND, and bitwise-OR). This version of the Knob & and Switch does not have a Control Unit. Instead, you must play the role of the control unit by selecting the input registers, ALU functions, and output registers by clicking on the appropriate knobs. When you click on the Execute button on the page, a single CPU cycle is simulated. You can play with this version of the Knob & and Switch simulator until you have a better feel for the CPU and what happens within a CPU cycle.
The Knob & Switch Computer with Memory
This version of the Knob & and switch simulator brings us closer to the von Nuemann architecture by adding main memory, where data can be stored and retrieved for calculations by the CPU. By clicking on switches, it is possible to direct data from the main memory to registers within a CPU cycle. Likewise, switches can be set so that the output of the ALU is directed to main memory as opposed to registers. You can play with this version of the Knob & and Switch simulator until you have a better feel for the way that data flows between the main memory and the CPU.


Practice Exercises

  1. Answer the following questions using the Basic Knob & Switch Computer:
    1. How must the knobs in the Knob & Switch Computer be set in order to subtract the contents of register R1 from register R3, and store the result in R2?
    2. How many CPU cycles would be required in order to add the contents of registers R0, R1, and R2 and store the result in R3? Describe the settings for each of the cycles.
    3. What is the fewest number of CPU cycles that you could use to quadruple the value stored in R1? You do not have to specify the knob and switch settings for each cycle. Rather, just describe the operation that would be performed during each cycle.
  2. Answer the following questions using the Knob & Switch Computer with Memory:
    1. Describe the knob and switch settings required to move the contents of Main Memory cell 7 into Register R0. Or, to describe the operation in pseudocode: R0 = M[7]
    2. Describe the knob and switch settings required to add the contents of Register R0 and Register R1 and store the result in Main Memory cell 5. In pseudocode: M[5] = R0 + R1
    3. Is it possible to move the contents of one Main Memory cell to another without changing the value? If so, describe the steps involved. For example, consider moving the contents of Main Memory cell 4 to cell 5: M[5] = M[4]
    4. How would you store 3 times the value contained in Main Memory cell 1 into Register R2? Describe the operation that would be performed during each CPU cycle (you do not have to specify the knob and switch settings).

Homework Assignment 1b

  1. For the von Neumann Architecture:
    1. What is meant by Stored Program (i.e. "Von Neumann") architecture?
    2. What are the three main parts of the Stored Program Architecture and what do they do?
    3. What are the three main parts of the CPU and what do they do?
    4. What is a CPU Cycle (or Instruction Cycle)?

  2. For the basic Knob & Switch Computer:
    1. How must the knobs in the Knob & Switch Computer be set in order to double the contents of register R2, and store the result in R1? For this problem and the ones below, your solution must work regardless of what value is in R2 and the other registers (ie, you must compute the desired value; you may not assume the desired value happens to be stored somewhere handy).

    2. How many CPU cycles would be required in order to negate (flip the sign) of the contents of register R1, and store the result in back in R1? Describe the knob settings for each of the cycles.

  3. For the Knob & Switch Computer with Memory:
    1. How many CPU cycles are required to add the contents of Main Memory cells 1 and 2, and store the result in Main Memory cell 3? Describe the knob and switch settings for each cycle. In pseudocode: M[3] = M[1] + M[2]
    2. What is the fewest number of CPU cycles that you could use to store 12 times the value contained in Main Memory cell 2 into Register R3? Describe the operation that would be performed during each cycle. For this problem, you do NOT need to describe the knob and switch settings needed for each instruction -- just describe the operation itself (ie, what the instruction accomplishes).