Visualizing the Fetch-Decode-Execute Cycle in a Simulator
Single-step a transparent teaching CPU, trace every register transfer, and distinguish instruction phases from clock cycles and modern processor pipelines.
TL;DR: Fetch-decode-execute is a conceptual sequence, not a promise that every instruction takes exactly three clocks. In a transparent multicycle CPU, fetch selects and reads an instruction, decode interprets its fields and prepares operands, and execute performs the operation and commits architectural state. The most useful simulator exercise is to predict each register transfer before stepping, then explain every observed change from an explicit microoperation.
A CPU schematic becomes much easier to understand when it is treated as a sequence of state changes rather than a page of boxes and wires. A simulator lets you pause after every clock edge and ask:
- Which register was allowed to load?
- Which source drove each bus?
- Which control signals were asserted?
- Which value changed, and why?
- What will the program counter select next?
This case study uses a deliberately small, word-addressed, multicycle teaching processor. It is not a description of x86, Arm, RISC-V, or every internal detail of the DigiSim template. Its purpose is to establish a trace method you can apply to the Sequential Instruction Executor or to a CPU you build yourself.
For the architecture-wide treatment—including caches, variable-length instructions, pipelining, speculation, and ISA differences—read the fetch-decode-execute deep dive.
The Teaching Datapath
Our trace assumes these visible blocks:
| Block | Role in this model |
|---|---|
| Program counter (PC) | Holds the word address used for the next sequential instruction fetch |
| Memory-address register (MAR) | Holds an address while the memory operation completes |
| Memory-data register (MDR) | Holds a word returned by memory or prepared for a write |
| Instruction register (IR) | Preserves the current instruction while it is decoded and executed |
| Register file | Holds programmer-visible operands and results |
| ALU | Performs arithmetic, logic, and comparisons |
| Flags register | Optionally preserves status such as zero, carry, sign, and overflow |
| Control sequencer | Selects sources, destinations, ALU operation, and memory intent for each microstep |
These registers are a teaching decomposition. A real implementation may combine, rename, duplicate, pipeline, or omit them. For example, a processor can hold multiple fetched instructions in queues rather than one instruction register, and a memory interface can hold requests in protocol state rather than one MAR.
Define the Model Before Tracing It
The trace is only meaningful if its conventions are written down. We will assume:
- memory is word-addressed
- every instruction occupies one word
- the normal next address is therefore
PC + 1 - memory read data is captured in a later microstep
- register writes occur on the active clock edge when their load enable is asserted
- the example register file has two read ports and one write port
- instructions update flags only when their definition says so
Byte-addressed or variable-length machines use a different PC increment. A faster memory can combine microsteps; a slower memory can insert wait states. Those are design choices, not contradictions.
Fetch as Explicit Microoperations
One possible three-step fetch is:
F0: MAR <- PC
F1: MDR <- MEM[MAR], PC <- PC + 1
F2: IR <- MDR
F0: Select the instruction address
The PC drives the path into the MAR, and MAR_LOAD is asserted. After the edge:
Nothing requires the PC to change in this microstep.
F1: Read memory and prepare the fall-through address
Memory returns the word selected by the MAR. The MDR captures it, while the PC incrementer prepares the next sequential word address:
Those transfers can occur together because they write different registers and use different datapath resources in this model.
F2: Preserve the instruction
The IR captures the MDR:
The memory data path is now free for a later load or store while the instruction bits remain stable for decode.
This sequence assumes the memory result is valid in F1. A handshake-based design would remain in a wait state until READY or an equivalent response arrives.
Decode Is More Than Naming an Opcode
Decode establishes what the instruction means under the teaching ISA:
- identify the instruction format
- determine whether the encoding is legal
- extract register indexes or an immediate value
- select source operands
- choose an ALU function or memory operation
- determine which architectural state may be updated
An instruction format might contain:
register form: opcode | source A | source B | destination
immediate form: opcode | destination | immediate
The bit positions and widths are ISA-specific. Do not transfer field labels from one format to another without checking the opcode first. The instruction-register and decode guide explains fixed- and variable-length formats in more detail.
In this small processor, decode may be combinational once the IR is loaded. “Decode phase” does not necessarily mean a dedicated clock cycle; it means the work that turns encoded bits into operand and control intent.
Execute and Commit
Execute depends on the instruction class.
Register arithmetic
For:
ADD R2, R0, R1
the logical work is:
A <- REG[R0]
B <- REG[R1]
R <- A + B
REG[R2] <- R
FLAGS <- status(R, carries)
With two combinational read ports, the register operands can reach the ALU in one microstep and the destination can capture the result on the following edge. A single-bus CPU may need separate transfers into temporary operand registers.
Load immediate
For:
LDI R0, 5
decode extracts the immediate field, extends it according to the instruction definition, and routes it to the destination write port:
Whether the immediate is zero-extended or sign-extended must be specified. The same raw bits can represent different values under those two rules.
Memory operation
A load or store can require:
- effective-address calculation
- memory request
- wait for response
- data capture or write completion
- optional register write-back
That is why “execute” often spans several cycles in a multicycle CPU.
Branch
A conditional branch computes or obtains:
- a branch condition
- a target address
- a fall-through address
Then a multiplexer selects the next PC value. If the branch is not taken, the incremented PC remains. If taken:
Flags are one possible condition source. Base RISC-V instead compares registers as part of its branch instructions. The program-counter guide covers these update sources.
Worked Program: Load, Load, Add
Use this abstract program:
| Word address | Instruction | Meaning |
|---|---|---|
| 0 | LDI R0, 5 | place 5 in R0 |
| 1 | LDI R1, 3 | place 3 in R1 |
| 2 | ADD R2, R0, R1 | place R0 + R1 in R2 |
| 3 | HALT | stop accepting new instruction work |
The exact binary encoding depends on the template or CPU you choose. Write its opcode table beside the trace rather than assuming the hex values from another teaching ISA.
Initial state
Assume reset establishes:
PC = 0
R0 = 0
R1 = 0
R2 = 0
controller = F0
Do not assume every memory or register clears unless reset or initialization explicitly provides it.
Trace
| Step | Microoperation | Important state after the edge |
|---|---|---|
| 1 | MAR <- PC | MAR=0 |
| 2 | MDR <- MEM[MAR], PC <- PC+1 | MDR=LDI R0,5, PC=1 |
| 3 | IR <- MDR | IR=LDI R0,5 |
| 4 | execute immediate write | R0=5 |
| 5 | MAR <- PC | MAR=1 |
| 6 | MDR <- MEM[MAR], PC <- PC+1 | MDR=LDI R1,3, PC=2 |
| 7 | IR <- MDR | IR=LDI R1,3 |
| 8 | execute immediate write | R1=3 |
| 9 | MAR <- PC | MAR=2 |
| 10 | MDR <- MEM[MAR], PC <- PC+1 | MDR=ADD R2,R0,R1, PC=3 |
| 11 | IR <- MDR | IR=ADD R2,R0,R1 |
| 12 | execute ALU write | R2=8; flags update if specified |
This program contains three instructions but twelve illustrated microsteps. Calling each instruction a “cycle” would hide the distinction between instruction count, microsteps, and clock cycles.
What to Observe in the Simulator
For every clock step, record:
| Signal or state | Question |
|---|---|
| controller state | Which microoperation is intended? |
| PC | Does it identify the correct next word? |
| MAR | Which memory address is held stable? |
| MDR | Which memory word was captured? |
| IR | Which instruction remains active? |
| source enables | Is exactly the intended source selected? |
| load enables | Which registers will change on this edge? |
| ALU operation | Does it match the decoded instruction? |
| write address/data | Is the correct destination receiving the correct value? |
| flags | Are they updated, held, or irrelevant for this instruction? |
A reliable trace has one explicit cause for every state change. If two sources are enabled onto a modeled shared bus, or if a register changes without a load enable, stop and diagnose the control logic.
A Better Lab Procedure
Pass 1: Predict
Before pressing Step:
- write the current controller state
- list asserted control signals
- calculate the next value of every register that can load
- identify registers that must hold
Pass 2: Observe
Advance one edge and compare actual values with the prediction. Record the first divergence rather than continuing with corrupted state.
Pass 3: Explain
For each mismatch, classify it:
- wrong instruction encoding
- wrong source selection
- wrong destination or load enable
- incorrect ALU function
- reset or initialization mismatch
- off-by-one PC update
- memory response timing mismatch
- branch condition or target error
Pass 4: Mutate one thing
Change ADD to SUB, change one immediate, or change one destination register. Predict exactly which microsteps and values should differ. A good architecture model makes local program changes produce explainable trace changes.
Verification Beyond One Program
The three-instruction trace is a worked example, not sufficient CPU verification. A useful test plan includes:
- every legal opcode
- representative legal register indexes and immediates
- illegal or reserved encodings
- arithmetic boundary cases
- load/store at address boundaries
- taken and not-taken branches
- branch target and fall-through behavior
- reset from several controller states
- halt or idle behavior
- wait states if memory can delay
- control invariants such as one bus source and one intentional write destination
For each instruction, define its architectural result independently of the microsteps. Then check that the final visible state matches even if the internal sequencing changes.
What This Model Does Not Claim
Modern processors do not generally fetch one instruction, finish it completely, then begin the next. They can:
- fetch several bytes or instructions together
- predict future control flow
- decode into internal operations
- overlap many instructions
- execute independent operations out of order
- wait on caches while other work proceeds
- retire results in architectural order
Fetch-decode-execute remains a valuable causal model, but a high-performance implementation divides and overlaps those responsibilities. “Three phases” is not a three-cycle performance equation.
The simulation also does not establish physical timing. A functional model verifies value and sequencing behavior. Maximum clock rate, setup/hold closure, clock skew, and routed delay belong to the target implementation and its timing tools.
Classroom Use
A concise 30-minute activity:
- Give students the instruction table and initial state.
- Trace the first
LDItogether. - Ask pairs to predict the second
LDI. - Have each pair trace the
ADDand explain every enable. - Replace
ADDwithSUBand compare only the affected signals. - Finish with one taken branch and one not-taken branch.
Grade the reasoning trace, not just the final value. A student who can explain why the PC, IR, source operands, and destination changed has learned more than one who reached R2=8 by trial and error.
Continue Learning
Open the Sequential Instruction Executor, identify its actual registers and instruction encoding, and adapt the trace table to what the template exposes. Treat the template’s labels and behavior as authoritative for that circuit.
Then study the components separately:
The exercise is complete when you can pause at any edge and predict every next-state change before the simulator reveals it.



