Chapter 1 · Simulation

A Simple CPU: Fetch–Decode–Execute

← Chapter 1

Instructions: 0 · Steps: 0

A Simple CPU: Fetch–Decode–Execute

Goal: See the stored-program concept and how the CPU processes every instruction with the fetch → decode → execute cycle, step by step. The program’s instructions and its data sit in the same memory (von Neumann architecture).

How to use it

  • Pick a sample program. Each press of Step runs one stage of the cycle; Play advances automatically and the Speed slider sets the pace. Run to end finishes the program at once; Reset reloads memory and registers.
  • Fetch: the address in the PC goes onto the address bus, a READ signal goes on the control bus, and the instruction arrives in the IR over the data bus; the PC is incremented.
  • Decode: the control unit splits the instruction in the IR into the opcode (operation code) and the address.
  • Execute: memory is read or written, the ALU computes, or a branch instruction changes the PC.
  • Try it yourself: before every “execute” stage you guess the new value of ACC, memory or the PC; correct answers are counted.

Registers

PC (program counter): the address of the next instruction. IR (instruction register): the fetched instruction. ACC (accumulator): the register where results are accumulated.

Instruction set

InstructionOpcodeMeaning
LOAD a0001ACC ← memory[a]
ADD a0010ACC ← ACC + memory[a]
SUB a0100ACC ← ACC − memory[a]
STORE a0011memory[a] ← ACC
JMP a0101PC ← a (unconditional jump)
JZ a0110if ACC = 0 then PC ← a (conditional jump)
HALT0000stop

The codes are hypothetical: in a 16-bit instruction the first 4 bits are the opcode and the last 12 bits are the address (e.g. ADD 1005 → 0010 001111101101). The codes of HALT, LOAD, ADD and STORE are the same as in the slides; SUB, JMP and JZ were added for this simulation.

Related slides: Chapter 1.3 · Computers (the Fetch–Decode–Execute Cycle, Buses, Instruction Encoding) and Chapter 1.2 · Computer Hardware.