Summary: You will explore a simple but complete instruction set architecture.
Collaboration: You will work with a randomly assigned partner during class.
Submitting: You do not need to turn in any work for this lab. If you are unable to finish all of the exercises during class time, you should complete this work on your own. So that we may transition to the MIPS datapath as a class, please notify the instructor when you complete Part D.
In this lab, you will explore a complete CPU architecture. Specifically, you will look at how an instruction is processed along the CPU datapath, how values from memory are incorporated into CPU instructions, and the fetch-execute cycle.
The Knob & Switch Computer uses metaphor and an incremental approach to demonstrate the interactions between CPU datapath, CPU control, and main memory. We use it in this lab to introduce the main concepts of computer organization before getting into the details of MIPS instructions and digital logic.
Open the K&S Datapath Simulator. If the link doesn’t open, then visit the Knob & Switch Computer and click the appropriate link.
This simple CPU contains four registers, but no control unit (or memory). That is because you will be the control unit! You direct which registers are operated on, and which operations are performed.
R1 to 42 by clicking on the zero and
typing in a new value. Then set the value of R2 to be
17.R1 and the B bus address to
R2 by clicking each appropriately. Note: A bus is
essentially a collection of wires used to transport data from one
component to another. A better animation would show the four bits
flowing along four wires.R1=42 and R2=17 again then “program”
the simulator to compute R3=R1-R2 and execute your
simulation.In this section, we add memory to the datapath and switches to direct traffic to and from it.
Open K&S Datapath Simulator with Main Memory. There are two new components: main memory and bus switches.
The main 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. (If you don’t see the main memory, try making the browser window larger.)
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. What digital components might these switches represent? (Not literal switches or individual transistors.)
Set Mem[1]=42. That is, put the value 42 into memory
location 1.
Select Mem[1] as the RW
location.
Find the main memory bus. Close the switch from the main memory bus to the C bus. Then open the switch from the ALU to the C bus. What do you think will happen when run an execute cycle along the datapath?
Click the Execute button and watch the data flow through the datapath. Is the result what you expected? You should notice two things:
If you did not see both those things, set Mem[1]=43 and
click Execute again.
How can we write data to memory? By closing the connection from the C bus to the main memory bus, as follows:
R0=8 and R1=9.R0+R1.Now everything should be set to add our registers and send the output from the C bus along to memory. Where in memory will the result be stored? Verify this by clicking Execute.
You may have noticed that the K&S architecture differs in a very important way from the MIPS architecture. What does K&S allow that MIPS does not?
Thought question: Suppose we wish to subtract Mem[6]
from Mem[7] and store the result in Mem[8].
That is,
Mem[8] = Mem[7] - Mem[6]
How many cycles would this take?
In this section, we add a virtual control unit to set the knobs and switches according to a stored program.
Open the K&S Simulator with Microprogramming. This simulation adds a Microprogram Memory, which contains binary numbers representing the positions of the knobs and switches.
xs disappear and binary numbers appear. Verify that
they correspond to the default settings of the knobs and switches, as
well as the memory RW address.Mem[7]=42, then configure the datapath and memory
to load this value into R0: R0=Mem[7]. Click the first
green arrow and notice how the binary values change.Mem[8]. Click the second green arrow to add this as the
second instruction.Mem[6] from Mem[7] and store the
result in Mem[8]. You can type directly in the microprogram
memory, if you prefer.In this section, we add the ability to store machine language instructions in memory.
Open the Complete K&S Computer Simulator.
Study the control unit. Find the instruction register (IR), the program counter (PC), and the micro-instruction register.
In Mem[0], type this assembly instruction:
add r1 r2 r3. (That is, you literally type those ASCII
assembly characters, not binary machine code or micro-instruction
fields.)
Let’s compare machine and asssembly versions of this instruction:
Enter the HALT instruction in
Mem[1].
Put some more interesting (i.e., non-zero) numbers in the registers, set the animation speed to Fast, and execute the program.
Open the reference card for the K&S ISA and find the instructions for accessing memory.
Mem[6] from Mem[7] and store the result in
Mem[8]. Be sure to end your program with a
HALT instruction.Referring to the K&S ISA reference, is the K&S ISA branching more like MIPS or ARM?
Thought question: What do you think the following program will do?
0: SUB R0 R0 R0 ; Mem[0]
1: LOAD R1 5 ; Mem[1]
2: ADD R0 R0 R1 ; Mem[2]
3: BRANCH 2 ; Mem[3]
4: HALT ; Mem[4]
5: 1 ; Mem[5]The last line is not a typo: Mem[5] should contain the
value 1.
Make it real:
Write a sequence of assembly instructions to multiply the value at memory address 11 by 4.
For example, if the contents of memory address 11 was the number 7, your instructions should store the number 28 there. While the ALU has no multiplication setting on its knob, multiplication can be accomplished via repeated addition: \(7\times4 = 7 + 7 + 7 + 7\).
Type your program into the simulator and execute it to verify its correctness.
The K&S ISA supports the instruction BZERO MMMMM,
which means, if the current ALU result is zero, set the program counter
to the memory address MMMMM. Use this instruction to write
a K&S program that uses a loop to multiply R0 and
R1, placing the result in R2. Your program may
change the value of R0 or R1 if necessary.
Notes:
HALT instruction at the end
of your program.Copyright © 2018–2025 Charlie Curtsinger and Jerod Weinman
This work is
licensed under a Creative Commons Attribution NonCommercial ShareAlike
4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San
Francisco, California, 94105, USA.