Zum Inhalt springen

English:CPU architecture and the fetch-execute cycle - Computing Year 10

Aus MOOCsWiki Staging
aiMOOC-Siegel aiMOOC

CPU architecture and the fetch-execute cycle - Computing Year 10

QR-Code



Introduction

Historical desktop system showing the processor, memory and storage in a wider machine
Gustavb’s exploded desktop illustration is system context. The processor’s internal components and signal paths are specified separately in the original functional sketch and trace; the picture is not an internal CPU diagram.

Identify CPU components and follow a complete simplified instruction cycle. Trace 4+6 and the required 9+4 example, distinguish addresses from values, and execute a safe bounded symbolic machine with explicit architecture assumptions and per-cycle evidence.


Identify processor components and the machine contract


Separate the job of each processor component

A central processing unit processes instructions. The control unit coordinates operations and the arithmetic logic unit performs arithmetic and logical operations. Registers hold small amounts of immediately used state, such as operands, an instruction or an address. These roles work together; the control unit does not itself perform every addition, and a register is not the same thing as an entire secondary-storage device.

Component Role in this lesson Common confusion to avoid
Control unit Interprets the instruction and coordinates the required transfers/operation It does not replace the ALU’s addition role
Arithmetic logic unit or ALU Computes the required arithmetic or logical result It is not the whole CPU or a file store
General-purpose registers R0,R1,R2 Hold operands and a destination value Register contents are not their register indices
Program counter or PC Identifies the next instruction address under the declared convention It does not hold the full program
Memory address register or MAR Holds the address used for the current memory access in our model An address differs from the value stored at that address
Memory data register or MDR Holds the symbolic instruction transferred from memory in our model It is not necessarily the next instruction’s address
Current instruction register or CIR Holds the instruction being decoded/executed in our model Its role differs from selecting the next address

Register names and detailed micro-operations vary by architecture. Some textbooks use instruction register or IR instead of CIR. Use the names required by the chosen specification while explaining the role. The model here explicitly declares its conventions rather than asserting that every real processor has this exact internal register layout.


Relate processor, memory and storage

Main memory supplies instructions and working data; secondary storage retains files more persistently. In a simplified stored-program system, the processor fetches instructions from memory rather than executing an entire high-level program in one indivisible action. Data and instructions need an agreed encoding and interpretation. The historical desktop image shows the wider physical context, not the internal gate layout of the CPU.

The address bus communicates which location is selected, the data bus carries transferred values, and control signals coordinate actions such as reading memory. This is a functional explanation; buses in modern systems can have different implementations and protocols. A drawn arrow needs a direction and a meaning. It is not proof that every wire always moves only one way or that all modern processors use a single shared physical bus.


Read the original model’s contract

We use a fictional instruction-slot-addressed teaching machine with three unsigned eight-bit data registers. Program addresses identify symbolic instruction entries, starting at zero. Each instruction occupies one model slot, so sequential fetch advances PC by one. A real ISA might use byte addresses and different instruction lengths; do not transfer this increment rule without checking its architecture.

Our symbolic instructions are ADD destination,left,right; NOP; and HALT. They are Python tuples for readability, not encoded machine instructions or executable instructions for an actual processor. The model has at most sixteen entries, no branch instruction and no hardware effects. It exposes conceptual state changes so that a learner can trace and test them.

CodeAI / Code.org: CPU, Memory, Input & Output. Distinguish processor and memory roles, then trace the separately specified fictional instruction model below. The video is not documentation of our invented instruction encoding. Original: CodeAI, How Computers Work: CPU, Memory, Input & Output. The written explanations and native tasks work without sound or the external player. For the core 55-minute sequence, allow five minutes for retrieval, ten for the component/representation explanation, twelve for a worked cycle, ten for guided tracing, thirteen for the changed-register transfer and five for reflection. Additional tests and activities support further practice. Annual Year 10 placement is editorial within the common GCSE/KS4 pathway.



Trace fetch decode execute and register write-back


Follow one complete fetch-decode-execute cycle

At the start of the required worked example, PC is zero and the data registers contain R0=4,R1=6,R2=0. Program slot zero contains ADD R2,R0,R1 and slot one contains HALT. These values and instructions belong to our fictional model. A register index identifies a register; its stored data value is a separate quantity.

Stage State or action Meaning
Fetch address MAR receives PC, so MAR=0 Select the next symbolic instruction slot
Fetch data MDR receives program[0] Transfer ADD R2,R0,R1 from main-memory model
Hold instruction CIR receives MDR Retain the instruction for decoding/execution
Advance sequential PC PC becomes 1 Under our declared one-slot convention, identify the next instruction
Decode Control unit identifies ADD,destination R2,sources R0 and R1 Select operands and the requested operation
Execute ALU computes 4+6 = 10 Arithmetic is carried out on the register values
Write back R2 becomes 10;R0 stays 4 and R1 stays 6 The stated destination receives the result

This is one complete simplified cycle for ADD. The next cycle fetches HALT from slot one, advances PC to two under the same convention and stops the model. The stopped PC may be one beyond the two supplied instruction entries; no further fetch occurs. It is not an attempt to read an invented instruction from address two.


Trace the required transfer with new operands

Now start again with PC zero, R0=9,R1=4,R2=0 and the same two-entry program. MAR selects zero, MDR receives the ADD instruction, CIR holds it and PC becomes one. The control unit decodes the same operation and register identities. The ALU uses the new contents, 9 and 4, giving 13; write back stores 13 in R2. Do not add the register indices zero and one, or reuse the previous example’s result ten.

Cycle Fetched address Instruction PC after fetch R0 R1 R2 after execute
1 0 ADD R2,R0,R1 1 9 4 13
2 1 HALT 2 9 4 13

Both examples use the same instructions but different starting data. Keeping instruction identity and operand value separate is essential to understanding a programmable machine. If a design instead stores the result in main memory, its stated instruction semantics must include the needed store operation; this model’s ADD writes only a data register.


Label a functional processor diagram

Draw main memory outside a CPU boundary. Inside the CPU draw a control unit, ALU, data registers and the named state registers PC,MAR,MDR,CIR. Connect PC to MAR for address selection; memory to MDR for the fetched instruction; MDR to CIR; CIR’s operation/operand fields to the control unit’s decoding role; source data registers to the ALU; and the ALU result to the destination register.

Use labelled address, data and control paths rather than decorative arrows. Our written connection list is the authoritative teaching diagram specification. A functional sketch may omit physical implementation detail, but it should not put the whole program inside the PC or route the sum calculation to the control unit instead of the ALU. Explain one transfer in your own words.


State what the cycle does not imply

A machine instruction is not necessarily a whole high-level source-code line. A single addition written in a high-level language may involve several machine operations depending on compilation, data representation and architecture. Fetch/decode/execute is a conceptual account of repeated instruction processing, not a claim that a complete program finishes in one clock tick.

Real CPUs can use pipelines, caches, multiple execution units and speculative techniques. Clock rate alone does not determine total task performance, and this simulation is not a benchmark. The point of the model is to explain responsibilities and observable changes, while keeping the simplified state transitions explicit and reproducible.



Execute test and evaluate a bounded processor model


Run the complete bounded symbolic machine

The program below validates its synthetic inputs, fetches and executes the declared symbolic instructions, and records a separate snapshot after every cycle. It neither runs supplied text as Python nor controls hardware. The instruction list is a deliberately limited data model; ADD,NOP and HALT are its complete allowed instruction set.

def run_machine(program, initial):
    if type(program) is not list or not 1 <= len(program) <= 16:
        raise ValueError("Use one to sixteen symbolic instructions")
    if type(initial) is not list or len(initial) != 3:
        raise ValueError("Use exactly three initial register values")
    if any(type(v) is not int or v not in range(256) for v in initial):
        raise ValueError("Registers require unsigned byte values")
    for instruction in program:
        if type(instruction) is not tuple or not instruction:
            raise ValueError("Each instruction must be a nonempty tuple")
        if instruction in (("NOP",), ("HALT",)):
            continue
        if len(instruction) != 4 or instruction[0] != "ADD":
            raise ValueError("Supported instructions are ADD, NOP and HALT")
        if any(type(v) is not int or v not in range(3)
               for v in instruction[1:]):
            raise ValueError("ADD register indices must be zero to two")
    registers = initial.copy()
    pc = 0
    carry = False
    trace = []
    for cycle in range(len(program)):
        mar = pc
        mdr = program[mar]
        cir = mdr
        pc = pc + 1
        opcode = cir[0]
        if opcode == "ADD":
            destination, left, right = cir[1:]
            full_sum = registers[left] + registers[right]
            registers[destination] = full_sum % 256
            carry = full_sum > 255
        trace.append({"cycle": cycle + 1, "MAR": mar, "MDR": mdr,
                      "CIR": cir, "PC": pc, "registers": registers.copy(),
                      "carry": carry, "halted": opcode == "HALT"})
        if opcode == "HALT":
            return {"registers": registers, "PC": pc,
                    "carry": carry, "trace": trace}
    raise ValueError("No HALT reached in the supplied program")

if __name__ == "__main__":
    program = [("ADD", 2, 0, 1), ("HALT",)]
    for initial in ([4, 6, 0], [9, 4, 0], [250, 10, 0]):
        result = run_machine(program, initial)
        print("Initial:", initial)
        for row in result["trace"]:
            print("Cycle", row["cycle"], "MAR", row["MAR"],
                  "CIR", row["CIR"], "PC", row["PC"],
                  "registers", row["registers"], "carry", row["carry"])

The first example finishes with registers [4,6,10], the required transfer with [9,4,13], and both have fetched HALT at MAR=1 with final PC=2. In the third example, 250+10 has full mathematical result 260. Eight-bit unsigned storage retains four and sets the carry flag True. The simplified flag is unsigned addition carry; signed overflow and other processor flags are not modelled.


Examine snapshots and state ownership

The function copies initial register values, leaving the caller’s list unchanged. Each trace row also copies the registers at that moment. If every row instead referred to the same mutable list, a later write could make earlier cycle records appear to have had the final values all along. A trace should preserve historical state, not only a final screenshot repeated across rows.

Use a three-entry program ADD R2,R0,R1; ADD R2,R2,R1; HALT with initial [4,6,0]. After cycle one R2 is ten; after cycle two it is sixteen; after cycle three it stays sixteen. The first trace snapshot must still show ten after the function returns. This test distinguishes correct per-cycle snapshots from an aliased mutable reference.


Choose tests that expose different defects

Test Expected result Purpose
ADD then HALT with [4,6,0] R2=10;two cycles;final PC=2 Mapped worked example
ADD then HALT with [9,4,0] R2=13;sources remain 9 and 4 Required changed-input transfer
ADD then HALT with [250,10,0] R2=4;carry True Declared eight-bit wrap and carry
HALT in first slot One cycle;registers unchanged;PC=1 Immediate termination
NOP then HALT Two cycles;registers unchanged Instruction with no data-register write
Two dependent ADDs then HALT Snapshots retain R2=10 then R2=16 Data dependence and independent history
Program without HALT ValueError after its bounded entries Missing stop is reported,not an infinite loop
Unknown opcode or invalid register index ValueError before execution Instruction contract enforced

Registers are integers from zero to 255, excluding Booleans despite Python’s relationship between bool and int. The program length is one through sixteen. All symbolic instructions are checked before execution; even unreachable entries after an early HALT must satisfy this teaching input contract. It does not emulate a real ISA’s fault handling.

Changing the destination to a source register is allowed: ADD R0,R0,R1 computes from the old R0 and R1 before storing the new R0. An implementation that overwrites a source too early can fail such cases. Compare each expected operand and write-back destination, not only whether some register happens to contain the right sum.


Connect a simple embedded task without overstating the model

A fictional low-power controller might repeatedly read an input, perform a comparison and update an output. Its processor still needs instructions and working state, while persistent storage holds firmware/settings when appropriate. Our three-instruction model lacks input/output, comparisons, branches, interrupts, timing and persistent storage; it cannot run that entire controller. Use it only to explain the arithmetic cycle inside a wider system.

For this course submit a labelled component/transfer sketch, the complete 4+6 and required 9+4 traces, full source and actual expected-versus-observed tests if executed. Include an explained defect or refinement, such as fixing aliased trace snapshots, and one specific architecture limitation. A paper trace is reasoning evidence; practical programming claims need reproducible execution and appropriate teacher review. No physical equipment work or national qualification is certified by this simulation.



Interactive Tasks


Quiz: Test Your Knowledge

Which component performs the stated addition? (The ALU using the selected register values) (!The control unit replacing every datapath operation) (!The secondary-storage filename) (!The program counter adding its address to every operand)



What is the role of the program counter in the declared model? (Identify the next instruction-slot address) (!Contain the complete program text) (!Store every image file) (!Replace the ALU result register)



Why does the model advance PC by one per sequential fetch? (Each symbolic instruction occupies one declared instruction slot) (!Every real instruction in every architecture is one byte) (!PC always counts the number of user files) (!All CPUs have exactly three registers)



What is written to R2 for the required operands 9 and 4? (13) (!10) (!1) (!94)



Which statement distinguishes MAR and MDR? (MAR holds an access address while MDR holds transferred instruction data here) (!They must always contain the same numeric sum) (!MAR is the entire operating system) (!MDR replaces every storage device)



What happens after the two-entry ADD then HALT program? (HALT was fetched at address 1 and the stopped PC is 2) (!The model must fetch an invented instruction at address 2) (!The ADD instruction executes an unlimited number of times) (!Both source registers are always erased)



What does the control unit do with the current instruction? (Decode its operation and coordinate the required actions) (!Store every permanent file) (!Perform every arithmetic operation instead of the ALU) (!Guarantee the speed of every real processor)



Why copy registers into each trace row? (Preserve each cycle’s historical snapshot when later state changes) (!Make all old snapshots become the final state) (!Turn the program into an actual hardware driver) (!Remove the need for any expected results)



What is the model result for unsigned byte operands 250 and 10? (Retained value 4 with carry True) (!Retained value 260 with no carry in eight bits) (!A guaranteed signed-overflow classification for every ISA) (!The source register indices added instead of the values)



What does the complete simulation establish? (Reproducible state changes under its explicit fictional contract) (!An actual CPU performance benchmark) (!That one high-level line is always one machine instruction) (!Legal permission to alter physical controller hardware)





Memory Game

Control unit Decodes the instruction and coordinates operations
ALU Computes arithmetic or logical results
Program counter Identifies the next instruction address in the declared convention
MAR Holds the selected memory-access address in this model
MDR Holds transferred instruction data in this model
CIR Holds the current instruction for decoding and execution





Drag and Drop

Select address Copy the declared next-instruction address from PC to MAR
Fetch instruction Read the selected memory entry into MDR and retain it in CIR
Decode operation Identify ADD and the source/destination register fields
Execute arithmetic Use the stored operand values in the ALU
Write back and continue Store the result at the declared destination and process the next instruction





Crossword Puzzle

REGISTER What small storage element holds immediate processor state?
DECODE Which stage interprets the instruction?
FETCH Which stage obtains an instruction from memory?
EXECUTE Which stage carries out the instruction’s operation?
ADDRESS What identifies the selected memory location?
CONTROL Which word completes the coordinating CPU unit’s name?





LearningApps

Optional extra practice. Choose an appropriate activity with your teacher. If the external collection is unavailable, use the native activities and independent tasks in this course.


Cloze Text

Complete the explanation.
The program counter identifies an instruction

. The current instruction is held in the

in our model. The control unit

the operation and coordinates transfers. The

adds the selected operand values. Nine plus four gives

. The declared ADD stores its result in a

. HALT stops this bounded

. A trace snapshot should preserve the state of its own

.



Open Tasks


Easy

  1. Explain three CPU components: Distinguish control unit, ALU and data registers.
  2. Separate an address from a value: Explain PC zero, fetched ADD and source value nine without treating them as interchangeable.
  3. Label state-register roles: Describe PC,MAR,MDR,CIR under this model’s stated convention.
  4. Trace the mapped 4+6 example: Name fetch,decode,ALU execution and R2 write-back with final ten.


Standard

  1. Complete the required 9+4 transfer: Give each stage and the two-cycle table ending R2=13,PC=2 after HALT.
  2. Draw a functional component sketch: Label CPU boundary,memory,registers and address/data/control connections.
  3. Run normal and boundary cases: Record actual results for the two sums,immediate HALT,NOP and unsigned carry.
  4. Test historical snapshots: Use two dependent ADDs and verify the first snapshot retains ten while the later one stores sixteen.


Advanced

  1. Change the destination safely: Test ADD R0,R0,R1 and explain when old operand values must be read.
  2. Diagnose a broken trace: Show how shared mutable register references can falsify earlier history and retest a correction.
  3. Evaluate the architecture abstraction: Explain instruction-slot addresses,symbolic tuple encoding and missing real-CPU features.
  4. Defend a processor portfolio: Combine components,required transfer,complete source,observed tests and a limitation without claiming hardware or qualification evidence.



Learning Check

  1. Required transfer cycle: Trace addition of register values nine and four.
  2. Mapped worked example: Explain the roles for four plus six.
  3. Register and bus meanings: Distinguish selected address,current instruction and data result.
  4. State and snapshot test: Explain the dependent-ADD test.
  5. Boundary and stop behaviour: Explain carry,HALT and invalid input.
  6. Architecture and practical limits: Evaluate what the model demonstrates.


Worked checks and assessment guidance

  1. PC zero selects slot zero through MAR;MDR receives ADD R2,R0,R1 and CIR retains it. Under the declared sequential convention PC becomes one. The control unit decodes the operation and register fields;the ALU calculates9+4=13 and writes R2=13. The next cycle fetches HALT at address one and stops with PC two.
  2. R0 holds four and R1 six;their indices zero and one are not the values to add. The control unit coordinates the ADD and the ALU computes ten. R2 receives ten while source registers remain four and six. The PC identifies an instruction address rather than storing the full program.
  3. MAR holds the chosen memory address,MDR the transferred instruction,CIR the instruction being decoded in this model. The address path selects a location,the data path carries transferred values,and control signals coordinate operations. Real architectures can implement these roles differently.
  4. With initial[4,6,0],ADD R2,R0,R1 stores ten,then ADD R2,R2,R1 stores sixteen. The first snapshot must remain ten after later writes. Copying register state per trace row preserves history;copying initial values prevents mutation of the caller’s list.
  5. 250+10 is mathematically260;the declared unsigned eight-bit result is four with carry true. HALT in the first slot stops after one cycle with PC one. A no-HALT program fails after its bounded entries,not an infinite loop. Wrong opcodes,register indices and types are rejected under the stated teaching contract.
  6. Each instruction occupies one symbolic model slot,so sequential PC advances by one;that is not a universal byte-addressed ISA rule. Python tuples are readable symbolic entries,not actual machine encoding. The model omits branches,interrupts,caches,pipelines,I/O and timing. Submit reproducible reasoning and actual tests without claiming a physical processor benchmark or practical hardware competence.


Learning evidence

Submit a component/transfer sketch with explicit PC,MAR,MDR,CIR,control-unit,ALU and data-register roles. Preserve the 4+6 and required9+4 complete cycle tables,full symbolic-machine source,expected/actual tests,independent trace snapshots and one reasoned revision or boundary. Label paper predictions separately from executed results and state architecture limits.


OER and Wikipedia

DfE GCSE Computer Science subject content is the common mapped baseline;Year10placement is editorial. Computation Structures: Instruction Set Architectures,Steve Ward provides primary teaching background on control/datapath separation,registers,stored programs and architecture-dependent interfaces. The simplified three-register instruction-slot machine,trace tables,code and feedback here are original;they do not reproduce or claim to implement that source’s Beta ISA. Reviewed14November2026.

Personal computer, exploded.svg, Gustavb, CC BY 2.5. Unchanged original; caption and learning activities are original.

https://www.youtube.com/watch?v=DKGZlaPlVLY — CodeAI / Code.org: How Computers Work: CPU, Memory, Input & Output;unchanged original publisher embed.


Linked learning areas


aiMOOC Projects



Schulfach+




aiMOOCs



aiMOOC Projekte









MOOCwiki · Deutsch

Nach dem Lernen ist vor dem Lernen

Entdecke direkt den nächsten Lernkurs. Weitere Inhalte erscheinen, wenn Du weiter nach unten scrollst.

Zur MOOCwiki-Hauptseite

Mediathek

Suche verfeinern

Dein Lernplan bestimmt, was oben steht. Alle anderen Inhalte bleiben erreichbar. Seitenaufrufe beeinflussen die Auswahl nicht.

Inhalte werden geladen ...

Mediathek wird aus dem Wiki geladen ...