Page 3: Inside the CPU: Registers, the ALU, and the Fetch-Decode-Execute Cycle

Knowing how the CPU fetches and executes instructions helps you reason about algorithmic instruction counts, branch mispredictions, and low-level CPU profiling metrics.

The Central Processing Unit (CPU) is the hardware engine that brings stored programs to life. Following the Von Neumann architecture, both program instructions and program data reside in addressable memory. The CPU continuously reads the next instruction from memory, decodes its operation code (opcode), and coordinates internal circuitry to execute the operation.

Even though modern superscalar processors employ branch prediction, out-of-order execution, and multiple cores, every CPU thread preserves the programmer-visible illusion of sequential instruction execution. Understanding registers, the Program Counter, and the Arithmetic Logic Unit (ALU) clarifies why tight loops run fast and why jumping unpredictably across memory slows execution down.

3.1 Architectural Building Blocks of a Processor

Inside a CPU core, data being actively computed is held in small, ultra-fast storage slots wired directly into the execution circuitry called registers. On a 64-bit architecture (such as x86-64 or ARM64), each general-purpose register holds 64 bits (8 bytes) and can be accessed in a single clock cycle (less than half a nanosecond).

Alongside general-purpose registers, a dedicated register called the Program Counter (PC)—or Instruction Pointer (IP)—holds the memory address of the next instruction to execute. Status flags track outcomes of the most recent ALU operation, such as whether the result was zero (Zero Flag) or negative.

3.2 The Fetch-Decode-Execute Cycle

At every tick of the system clock, the processor advances through three conceptual stages: Fetch, Decode, and Execute.

During Fetch, the CPU reads the instruction bytes located at the address in the Program Counter and increments the Program Counter to point to the following instruction. During Decode, the Control Unit inspects the instruction opcode and identifies which registers or memory addresses are involved. During Execute, the ALU computes the result and writes it back to the destination register or memory location.