Explain/ free interactive explanationsExplore explanations

How does a CPU run an instruction?

Explore the drawing, then read the explanation and its limits.

How does a CPU run an instruction?. Read the explanation and named parts below for a text alternative.

Loading the drawing…

Loading…

Controls become available when the drawing is ready.

Playback time is illustrative, not a real-world rate. Labels off hides annotations; the facts and limits below stay visible.

Parts

Hover or focus to highlight; tap to pin or release.

Explanation

A CPU instruction can be explained in three broad steps: fetch, decode and execute. Fetch brings instruction bits into a form ready to interpret. Decode identifies the operation to perform. Execute carries it out. This demonstration follows a single addition instruction, using readable text in place of the encoded bits a processor would use.

The example begins with five in register R1 and three in register R2. The arithmetic and logic unit, or ALU, adds them. The result, eight, is written back into R1, while R2 remains three. A program counter selects the instruction address. Here it advances from hexadecimal 100 to 104 for an example four-byte instruction.

The instruction notation is invented for teaching, not the syntax of a particular processor. The three steps do not imply three clock cycles or exactly three physical pipeline stages. Real pipelined processors can overlap work on several instructions. Moving sparks show the dependencies of this one example, rather than measured transfer speeds or electrical charges.

Source lines for every paragraph (JSON)

Facts and simplifications

The facts below use the library’s ledgers and their stated simplifications. References are inherited from the library’s offline ledgers; external sources have not been newly checked.

Basis and source status · docs/hardware/FACTS-HARDWARE.md

Based on the hardware fact ledger’s computer-organization and digital-design references. One invented addition instruction illustrates dependencies; three steps do not mean three clock cycles or pipeline stages.

Source: docs/hardware/FACTS-HARDWARE.md, lines 20–23, 60–73.

Ledger line 60: “Fetch, decode, execute”; numbered “1 Fetch”, “2 Decode”, “3 Execute”
docs/hardware/FACTS-HARDWARE.md:60 | “Fetch, decode, execute”; numbered “1 Fetch”, “2 Decode”, “3 Execute” | Instructions can be explained as fetching, interpreting, then carrying out an operation. | CO/DD/CS, basic processor cycle. **Simplified:** conceptual phases, not exactly three physical pipeline stages or three clock cycles. |
Ledger line 61: “One instruction: ADD R1, R2 (R1 gets R1 + R2)”
docs/hardware/FACTS-HARDWARE.md:61 | “One instruction: ADD R1, R2 (R1 gets R1 + R2)” | This example adds two register values and replaces R1 with the result. | DD/CO, register arithmetic. **Invented teaching notation:** this is a two-operand pseudoinstruction, not a claim about a particular RISC-V/x86/ARM instruction encoding or syntax. |
Ledger line 62: “Memory / cache”, “ADD R1, R2”; “Instruction reg.”; “(waiting)”
docs/hardware/FACTS-HARDWARE.md:62 | “Memory / cache”, “ADD R1, R2”; “Instruction reg.”; “(waiting)” | Fetch obtains instruction bits and makes them available for decode; the pre-fetch display waits. | CO/CS, instruction fetch. **Simplified:** assembly text stands in for encoded bits; the store abstracts the memory hierarchy. It does not assert a DRAM read for every instruction. The instruction register is a basic teaching model, not a required standalone register in every CPU. |
Ledger line 63: “PC”, “PC: 0x100”, “PC: 0x104”; “PC selects an instruction address.”
docs/hardware/FACTS-HARDWARE.md:63 | “PC”, “PC: 0x100”, “PC: 0x104”; “PC selects an instruction address.” | The program counter identifies the instruction address; a sequential instruction can advance it. | CO/DD. **Example:** fixed 4-byte instruction, address 256 then 260 decimal. No branch, variable instruction length, exception or fetch queue is modeled. |
Ledger line 64: “Control unit”, “Decode ADD”; “The control unit interprets the instruction.”
docs/hardware/FACTS-HARDWARE.md:64 | “Control unit”, “Decode ADD”; “The control unit interprets the instruction.” | Decode identifies what operation to perform. | CO/DD, opcode decoding/control. **Simplified:** immediate/special fields and register-address decoding are not expanded. |
Ledger line 65: “ALU”, “5 + 3 = 8” (or the custom `a + b = result`), “Operands go to the ALU; it adds them.”
docs/hardware/FACTS-HARDWARE.md:65 | “ALU”, “5 + 3 = 8” (or the custom `a + b = result`), “Operands go to the ALU; it adds them.” | ADD applies addition to the register operands. | DD/CO; arithmetic checked. Operands are bounded integers 0..99, so the model's largest result is 198; no fixed-word overflow or flags are claimed. |
Ledger line 66: “R1: 5 R2: 3” then “R1: 8 R2: 3”; “Writeback: the result is now in R1.”
docs/hardware/FACTS-HARDWARE.md:66 | “R1: 5 R2: 3” then “R1: 8 R2: 3”; “Writeback: the result is now in R1.” | The computed result is written to the destination, preserving R2. | CO, register writeback. **Simplified:** writeback is grouped into execute, not presented as a separately numbered stage. |
Ledger line 67: Address -> source; source -> instruction register; instruction register -> control; control -> ALU; register operands -> ALU; result -> registers
docs/hardware/FACTS-HARDWARE.md:67 | Address -> source; source -> instruction register; instruction register -> control; control -> ALU; register operands -> ALU; result -> registers | Order of the example's dependencies. | CO/DD, datapath flow. **Not to scale:** sparks loop for emphasis during a phase; they are not transfer counts, buses, actual timing or charges. No load/store operation appears. |
Ledger line 68: “Teaching sequence; pipelined CPUs overlap instruction stages.”
docs/hardware/FACTS-HARDWARE.md:68 | “Teaching sequence; pipelined CPUs overlap instruction stages.” | Real processors can overlap work on multiple instructions. | CO/CA, pipelining. The display deliberately presents one instruction in isolation. |