digiwleeaLearn
Open the lab →

Fetch

Reading the next instruction from memory

3 min read

Fetch is the first phase of every instruction: the CPU reads the byte at the program counter's address out of RAM into the instruction register, then increments the program counter so it points at the following instruction.

The CPU lesson runs the whole fetch-decode-execute loop at once. This page slows down the first phase, fetch, because it is the one step that is identical for every single instruction.
Fetch answers one question: what is the next instruction? The program counter already holds its address. So fetch drives that address to memory, reads the instruction byte back, and parks it in the instruction register where decode can examine it. Then it bumps the program counter so the machine is ready for the instruction after this one.
  1. The program counter puts its address on the bus (this is the address of the next instruction).
  2. RAM reads out the byte stored at that address, the instruction, onto the bus.
  3. The instruction register latches that byte, holding it steady for the rest of the cycle.
  4. The program counter increments (PC = PC + 1), so it now points at the following instruction.
Every instruction, whether a LOAD, an ADD, a STORE, or a HALT, begins with exactly these steps. Fetch does not care what the instruction *is*; it just retrieves it. Deciding what to do with it is the next phase, decode.
The endpoint of fetch: the instruction register (IR8) latching a fetched byte. Set I0-I7 to an instruction byte (this stands in for RAM's output), pulse LD, and the byte is captured, its opcode on OP0-OP3 and operand on AR0-AR3 ready for decode. Before a load the outputs read Z.
Common mistakes. The program counter increments during fetch, not at the end of execute, so during execute the PC already points at the *next* instruction (this matters for how jumps compute their target). On a single shared bus, fetch actually uses the bus twice (the PC drives the address, then RAM drives the byte back), so it is really two bus phases even though we describe it as one step. And the instruction register must hold the byte through decode and execute; if it were not latched, the changing bus would corrupt the instruction mid-cycle.
Try it
Which registers change during fetch, and which one stays put?

Frequently asked

What happens during the fetch phase?

The program counter drives the address of the next instruction to RAM, RAM reads that instruction byte onto the bus, the instruction register latches it, and the program counter increments. This retrieves the instruction and readies the machine for the one after it.

Why is fetch the same for every instruction?

Because fetch only *retrieves* the instruction; it does not act on it. Reading a byte from the address in the program counter and latching it into the instruction register is identical whether the byte turns out to be a LOAD, an ADD, a STORE, or a HALT. The differences appear later, in decode and execute.

When does the program counter increment?

During fetch, right after the instruction is read. So by the time the instruction executes, the program counter already points at the following instruction, which is why a jump loads an absolute target address rather than adjusting the current value.
With the instruction now sitting in the instruction register, the next phase, decode, splits it into an opcode and operand and works out which control lines to raise.

Every lesson here builds toward one thing: a working CPU, from the transistor up.

Open the free lab →
Builds towardDecode
Found this useful? Share itShare on X