Instructions for First CPU Simulator Exercise
Bring up the
Simple CPU Simulator
referred to in these instructions in a separate, side-by-side browser
window, if you haven't already.
Write your answers to the questions below in the
provided Markdown template
and submit it to Kit.
Hint: you can reset the CPU Simulator back to its initial condition
at any time by reloading the page.
The set of assembly language instructions that this CPU Simulator can
execute appears at the bottom of this page.
Getting Started
-
Translate the assembly language program that is provided when you
load the CPU Simulator page to machine code by clicking on the "==>"
button between the program and the main memory columns.
[This translation process is called "assembling", and the
software that does the translation is called an "assembler".]
What changed in the simulator as a
result? If you\'re not sure, reload the page and assemble the
program again. Why did the assembler translate the number of lines
that it did — why not more or less?
-
Enter address 0 (or 00) into the Instruction Address or Program
Counter (PC) field. Click on the "Fetch" button. What happened in
the simulator?
-
What do you think will happen when you click on the "Execute"
button? Write your answer before executing. Also
write down the values in any registers or memory addresses that you
think might change as a result of executing this instruction.
Now execute the instruction by clicking on the
"Execute" button. What happened? Write down your actual results
and see if they match your expected results.
Expected Results | |
Actual Results |
| | |
| | |
| | |
-
Continue to Fetch and Execute until the simulator halts. How many
cycles are required?
-
How many Fetch/Execute cycles do you think would be needed to add
the contents of R0, R1, and R2 and put the result in R3? Document
your expected results. Modify the assembly language and test your
hypothesis. (Don\'t forget the HALT instruction.)
Document the program you used and the actual number of
cycles required, including the cycles needed to halt the program.
Expected Results | |
Actual Results |
| | |
| | |
| | |
Assembly Language
Program: |
Playing with the Program Counter
-
Using your program from question 5, experiment with different start
instructions. (Assuming you execute the HALT instruction each time
you test your program, you will have to reload the page and re-type
in your program for each question below.)
- What happens if you start at address 1?
- What happens if you start at address 5?
- What happens if you start at address 9?
- What happens if you start at address 14?
-
What happens if you change the Instruction Address (PC) mid-program?
For example, what happens if you change the PC to 01 just
before fetching the HALT instruction? (In other words, if your HALT
instruction is in memory location 02, change the PC from 02 to 01
before fetching instruction 02.)
-
What happens if you Fetch multiple times before you click the
Execute button?