2. Computer Organization

The Fetch-execute Cycle

The Fetch-Execute Cycle

students, when you press a key, open an app, or play a game, your computer is doing something incredibly fast behind the scenes ⚡. It is not “thinking” like a person, but it is repeating a simple set of steps over and over to carry out instructions. This process is called the fetch-execute cycle. It is one of the most important ideas in Computer Organization because it explains how the CPU reads instructions, understands them, and carries them out.

In this lesson, you will learn how the cycle works, the key parts involved, and why it matters in IB Computer Science SL. By the end, students, you should be able to explain the stages of the cycle, use the correct terminology, and connect the cycle to the way a computer system is organized.

What Is the Fetch-Execute Cycle?

The fetch-execute cycle is the repeating process the CPU uses to run a program. A program is stored in memory as a sequence of instructions, and the CPU handles them one at a time. Each instruction tells the computer to do something, such as adding numbers, moving data, or comparing values.

The cycle usually has these main stages:

  1. Fetch the next instruction from main memory.
  2. Decode the instruction to understand what it means.
  3. Execute the instruction.
  4. Store the result, if needed, and then move to the next instruction.

This cycle happens extremely quickly, millions or even billions of times per second in modern computers. The CPU uses registers to help it manage the process. Registers are tiny, very fast storage locations inside the CPU. Important registers include the Program Counter $PC$, the Current Instruction Register $CIR$, and the Memory Address Register $MAR$.

The fetch-execute cycle is a central part of the von Neumann architecture, where instructions and data are stored in the same main memory. This is a key idea in computer organization because it shows how hardware components work together to turn stored instructions into action.

Stage 1: Fetching the Instruction

The first step is the fetch stage. The CPU needs to know which instruction to process next, and that address is kept in the $PC$. The $PC$ stores the memory address of the next instruction to be fetched.

Here is a simple version of what happens:

  • The value in the $PC$ is copied to the $MAR$.
  • The memory location in the $MAR$ is accessed.
  • The instruction at that address is copied into the $MDR$ or memory data register.
  • The instruction is then copied into the $CIR$.
  • The $PC$ is updated so it points to the next instruction.

This is similar to a librarian using a catalog card to find the next book on a shelf 📚. The address is the “location,” and the CPU uses it to get the correct instruction from memory.

For example, imagine a program with these instructions:

  1. Add two numbers.
  2. Store the answer.
  3. Display the result.

If the first instruction is at address $1000$, then the $PC$ might begin at $1000$. The CPU fetches the instruction at $1000$, and then the $PC$ changes to $1001$ so the next instruction can be fetched later.

Stage 2: Decoding the Instruction

After the instruction is fetched, it must be decoded. Decoding means the control unit interprets the instruction so the CPU knows what to do.

An instruction usually contains two important parts:

  • the opcode, which tells the CPU the operation to perform
  • the operand, which tells the CPU where the data is or what data to use

For example, an instruction might mean “add the value in memory address $2000$ to the value in register $A$.” The opcode would be the add command, and the operand would be the location or value involved.

The Control Unit is responsible for decoding. It sends signals to other parts of the CPU so the correct action happens. These signals may tell the Arithmetic Logic Unit $ALU$ to add numbers, tell registers to load data, or tell memory to send or receive information.

A useful way to think about decoding is like reading a recipe card 🍳. Fetch gives you the card, and decode helps you understand whether the next step is to mix, heat, or measure something.

Stage 3: Executing the Instruction

Once the CPU knows what the instruction means, it moves to the execute stage. This is where the actual operation takes place.

Execution depends on the type of instruction:

  • If the instruction is arithmetic, the $ALU$ may add, subtract, multiply, or divide.
  • If it is a data movement instruction, the CPU may copy data between registers and memory.
  • If it is a comparison, the CPU may check whether one value is larger than another.
  • If it is a jump or branch instruction, the CPU may change the value in the $PC$ so the program goes somewhere else.

For example, suppose a computer must calculate $7 + 5$. The instruction is fetched and decoded, then the $ALU$ performs the addition and produces $12$.

Some instructions take more than one clock cycle to complete. The CPU’s clock provides timing signals so the stages happen in an orderly way. This timing is important because every part must work together without confusion.

Stage 4: Storing the Result and Moving On

Many textbooks combine storing with execution, but it is helpful to think about it as the result being saved after the operation. If the instruction produces a result, that result may be written back into a register or memory location.

For example, if the instruction says to add two values and store the answer in memory address $3000$, then after the $ALU$ finishes, the result is copied to that location.

After that, the cycle begins again. The $PC$ now points to the next instruction, and the CPU repeats the process. This repetition is why computers can carry out entire programs without needing a person to approve every step.

The cycle can be summarized as:

$$Fetch \rightarrow Decode \rightarrow Execute \rightarrow Store \rightarrow Fetch \rightarrow Decode \rightarrow Execute \rightarrow Store \dots$$

How the Registers Work Together

The fetch-execute cycle depends on several special registers. students, you should know the role of each one because IB Computer Science often asks for terminology and process explanations.

  • $PC$: holds the address of the next instruction to fetch
  • $MAR$: holds the memory address that is being accessed
  • $MDR$: holds data or instructions moving to or from memory
  • $CIR$: holds the current instruction being decoded and executed

A typical flow is:

  1. $PC$ sends an address to $MAR$.
  2. Memory returns the instruction to $MDR$.
  3. The instruction is copied to $CIR$.
  4. The control unit decodes the instruction.
  5. The CPU executes it.
  6. The result is stored if needed.

This register system makes the CPU efficient because it avoids constant slow access to main memory. Registers are much faster than RAM, so moving important data into registers helps the CPU work quickly.

Why the Fetch-Execute Cycle Matters in Computer Organization

The fetch-execute cycle is not just a memory trick; it is a core part of how computers are built and how they function. Computer organization is about the arrangement of hardware components and how they work together. The CPU, memory, buses, and control signals all cooperate during the cycle.

This topic connects to several bigger ideas:

  • CPU design: the control unit and $ALU$ must coordinate instruction processing
  • Memory: instructions and data are stored in main memory
  • Buses: address, data, and control buses carry information between components
  • Performance: faster CPUs and better memory systems can improve cycle speed

A computer with a faster clock rate can usually complete more cycles per second, although overall speed also depends on other factors such as instruction complexity and memory access time. In real systems, modern CPUs may also use techniques like pipelining and caching to improve performance, but the basic fetch-execute idea still remains at the heart of how programs run.

Real-World Example: Playing a Game 🎮

Imagine students is playing a racing game. The game must keep checking the player's position, drawing the screen, updating scores, and responding to button presses.

Each of these actions is carried out by many instructions. The CPU repeats the fetch-execute cycle for each instruction:

  • fetch the instruction for updating the car position
  • decode it to see what calculation is needed
  • execute the calculation
  • store the updated position
  • move to the next instruction

If the game includes collision detection, the CPU may compare two values, such as whether the car’s position overlaps an obstacle. If the answer is yes, the game may trigger a crash animation. All of this depends on instructions being fetched and executed in order.

This example shows why the fetch-execute cycle is essential: without it, software would not run.

Conclusion

students, the fetch-execute cycle is the repeating process that allows a CPU to run instructions from a program. The main stages are fetch, decode, execute, and store. Registers such as the $PC$, $MAR$, $MDR$, and $CIR$ help the CPU manage each step. This cycle is a major part of Computer Organization because it explains how the CPU, memory, and control system work together to process instructions efficiently.

For IB Computer Science SL, you should be able to describe the cycle clearly, use the correct terms, and explain how it fits into the wider structure of a computer system. If you can trace one instruction from memory through the CPU and back to memory, you understand one of the most important ideas in computing.

Study Notes

  • The fetch-execute cycle is the process the CPU uses to run program instructions.
  • The main stages are fetch, decode, execute, and store.
  • The $PC$ holds the address of the next instruction.
  • The $MAR$ holds the memory address being accessed.
  • The $MDR$ holds data or instructions moving to or from memory.
  • The $CIR$ holds the current instruction being decoded and executed.
  • The control unit decodes instructions and sends control signals.
  • The $ALU$ performs arithmetic and logical operations.
  • The cycle repeats continuously while a program is running.
  • The fetch-execute cycle is a core idea in computer organization and the von Neumann architecture.
  • Faster hardware, caching, and pipelining can improve performance, but the basic cycle still remains important.
  • Understanding this cycle helps explain how software becomes action on a computer.

Practice Quiz

5 questions to test your understanding

The Fetch-execute Cycle — IB Computer Science SL | A-Warded