Fetch–Decode–Execute Cycle

Example: consider some computer program that has an instruction to add two numbers; this instruction, along with the other instructions of the program, is stored in main memory.

  1. First, the CPU fetches the addition instruction from memory, using the program counter to find its address in memory.
  2. Next, the CPU decodes the instruction, identifying it as an addition operation with two operands.
  3. Finally, the CPU executes the operation using a Ripple-Carry Adder circuit in the ALU: it adds the numbers and stores the result in a specified memory location or CPU register.

This simple example illustrates how the fetch–decode–execute cycle enables the CPU to perform even complex tasks step-by-step.

Why can't we store all of the instructions of a program directly on the CPU? Why do we use RAM?
Answer: The CPU has only several register in it, so its space is limited. Programs, especially long ones, simply won't fit into these registers, so they must be kept in a larger container: main memory.