Keep the levels of explanation separate
At the top level you write Python. The program might contain total = total + amount, which describes what should happen to two values. CPython typically compiles source to bytecode and runs it using the Python runtime. Bytecode is a format for that runtime, while the physical processor executes machine instructions from its own instruction set. In the browser this lab uses Pyodide and WebAssembly, so another runtime is involved. A Python variable or line is useful when tracing a program. A register or an instruction address is useful when tracing a processor. Do not assume one line corresponds to one machine instruction or one register.
Explain the stored-program model step by step
In the model on this page, main memory holds instructions and data. An address identifies a location; the value at that address can be an instruction or a piece of data. During fetch, the processor uses the program counter (PC) to identify the next instruction address. The address is copied to the memory address register (MAR). A memory read transfers the contents to the memory data register (MDR). The instruction is copied to the current instruction register (CIR) and the PC advances. The control unit then decodes the operation and any operand. Execution can involve the ALU, another memory access or a change to the PC.
| Moment | PC | MAR | CIR | ACC | What changed |
| --- | --- | --- | --- | --- | --- | --- |
| Before the first fetch | 0 | — | — | 0 | Next instruction is at address 0 |
| After fetching LOAD 6 | 1 | 0 | LOAD 6 | 0 | Instruction read, PC advanced |
| After executing LOAD 6 | 1 | 6 | LOAD 6 | 4 | Operand read from address 6 |
| After executing ADD 7 | 2 | 7 | ADD 7 | 11 | ALU adds the value at address 7 |
| After executing STORE 8 | 3 | 8 | STORE 8 | 11 | Address 8 now contains 11 |
Use Next step in the model and compare the registers with the table. After fetch, the MAR can still contain the instruction address, while the CIR holds the instruction that was read. After execution, the MAR can contain a data address. For STORE 8, the number 8 is an address, not the number stored. The data bus carries the value 11 in this example. The address bus identifies where it goes and the control signals request a write.
Explain how a loop changes the next instruction
The model shows straight-line execution until HALT. A branch instruction can set the PC to another address. For example, a conditional branch might return to an earlier instruction if a counter is above zero. Fetch then uses that earlier address. This is how the next instruction can differ from the next one in memory. A loop in Python has the same high-level idea, but it runs through the runtime. Avoid trying to map each Python statement directly onto the simple model's registers.
Place memory, storage and software in the picture
RAM holds the instructions and working data needed by running programs. It is normally volatile. Secondary storage, such as an SSD, keeps saved files when power is off. A cache stores copies of frequently or recently used data and instructions closer to the processor. The operating system manages resources such as memory, files, processes and devices. When you open a Python file in an IDE, the file may be on an SSD, the editor and runtime work with data in RAM, and the processor executes the instructions that carry out the work. Saving the script writes it to storage. Running it does not automatically save your edits or its output. In this browser lab, files made by Python are temporary unless you export what you want to keep.
Practise the distinction between a model and the real machine
Imagine a simplified program with LOAD 6, ADD 7, STORE 8 and HALT at addresses 0–3, but change the data to 10 at address 6 and −3 at address 7. Write the accumulator after each execute phase, the PC just after fetching STORE 8, and the value saved in address 8. Describe which part of the CPU performs the addition and what the control unit does when it decodes STORE. Then explain why tracing acc = acc + memory[1] in Python does not tell you exactly which registers a real CPU uses.
Explain performance with a workload in mind
A higher clock frequency can allow more cycles per second. More cores can help if work can run in parallel. A larger cache can reduce slower memory accesses if it keeps the data the program reuses. Explain the condition rather than assuming one specification determines performance.