Introduction
The CPU is the central component of a computer that executes program instructions. Surprisingly few people, however, understand how a CPU actually executes those instructions.
For example, running the ls command displays a directory listing, a web server processes HTTP requests, and a database executes SQL. These may appear to be entirely different operations. In reality, the CPU repeatedly executes simple instructions—such as addition, comparison, and reading or writing data—at very high speed.
The CPU repeatedly retrieves instructions from memory, interprets them, and performs the specified operations. This process is commonly explained using the instruction execution cycle, one of the most important concepts for understanding basic CPU operation.
Understanding the instruction execution cycle reveals the roles of internal CPU components such as registers, the program counter, and the ALU. It also provides a foundation for understanding Linux mechanisms such as processes, the CPU scheduler, and context switches.
What Is an “Instruction” Executed by the CPU?
A CPU executes programs, but it does not understand programs themselves. It can understand only very simple operations called instructions.
Examples of instructions executed by a CPU include the following.
• Read data from memory
• Write data to memory
• Add or subtract numbers
• Compare two values
• Change the execution location based on a condition (branching)
Each instruction is extremely simple, but complex programs are created by combining them. When a user runs the ls command, for example, the CPU does not directly perform an operation called “display a directory listing.”
Instead, it executes the individual instructions required to obtain directory information, ultimately causing the directory listing to appear on standard output.
Likewise, when Apache processes an HTTP request or PostgreSQL executes SQL, the CPU performs basic instructions such as addition, comparison, memory reads and writes, and conditional branches.
The CPU also cannot directly understand programming languages such as C, C++, and Rust. A compiler converts source code written in these languages into machine code that the CPU can understand.
Consider the following C code, for example.
int c = a + b;
From the CPU’s perspective, this operation is also decomposed into multiple instructions, such as “load a,” “load b,” “add them,” and “write the result.”
Conceptually, a program consists of a sequence of simple instructions executed by the CPU. Modern CPUs improve performance by processing multiple instructions concurrently using techniques such as pipelining, superscalar execution, and out-of-order execution.
The next section examines the instruction execution cycle in detail to explain the sequence through which a CPU executes these instructions.
The Basic Instruction Execution Cycle
The CPU does not execute all the instructions in a program at once.
Instead, it rapidly repeats a sequence in which it fetches one instruction, decodes it, and executes it. This sequence is called the instruction execution cycle.
Broadly speaking, the instruction execution cycle proceeds as follows.
- Fetch (retrieve the instruction)
- Decode (interpret the instruction)
- Execute (perform the instruction)
- Memory Access (Load/Store, if needed)
- Proceed to the next instruction
Note: This is a simplified conceptual model, not a universal set of hardware pipeline stages. Load/Store applies only when memory access is required, and “Proceed to the next instruction” represents the continuation of instruction processing. Real CPUs process multiple instructions concurrently using mechanisms such as pipelining, superscalar execution, and out-of-order execution.
Let us first look at the overall sequence.

We will examine each operation in order.
1. Fetch (Retrieving the Instruction)
First, the CPU retrieves the next instruction from the program stored in memory.
The address held by the Program Counter determines which instruction is retrieved. The CPU refers to this address, fetches the instruction, and proceeds to the next stage.
2. Decode (Interpreting the Instruction)
The fetched instruction cannot be executed as-is.
The CPU’s instruction decoder analyzes it and identifies the operation type, such as addition, loading data, or conditional branching. It then determines which circuitry will perform the operation.
3. Execute (Performing the Instruction)
Once the instruction has been understood, the CPU performs the actual operation.
The ALU (Arithmetic Logic Unit), for example, handles addition, subtraction, magnitude comparisons, and logical operations. For a conditional branch instruction, the CPU determines the address of the next instruction to execute.
4. Memory Access (Load/Store, If Needed)
Some instructions need to use data in memory or save their results to memory.
A Load reads data from memory into the CPU. A Store writes a result produced by the CPU to memory.
For example, loading a variable’s value for a calculation uses a Load, while saving the calculation result to memory uses a Store.
Load and Store are not performed for every instruction; they are used only by instructions that require memory access.
Note: About Write Back
Some CPU documentation includes a stage called Write Back in the instruction execution cycle.
Write Back is the operation of writing a computation result back to a register. It is often treated as an independent stage in RISC processors and similar architectures, while broader explanations of CPU operation may describe it as part of Execute or Load/Store.
Because memory access is particularly important for understanding Linux systems, this article focuses on Load/Store.
The CPU Repeats This Cycle
The CPU continuously repeats this instruction execution cycle.
Even when executing the ls command, the CPU does not perform “display a directory listing” all at once. The listing is eventually displayed because the CPU repeatedly fetches, decodes, and executes instructions and accesses memory when necessary.
The same applies to large software packages such as Apache and PostgreSQL. No matter how complex a program is, the CPU’s fundamental operation remains the same.
The CPU achieves its high performance by repeating this instruction execution cycle at extremely high speed.
The Role of Registers
If the CPU had to read data from memory every time it executed an instruction, processing would take too long. Registers address this problem.
Registers are extremely fast storage locations inside the CPU. The CPU stores the data and addresses required for instruction execution in registers and uses them while processing instructions.
CPUs commonly perform calculations using values held in registers. In a simplified example, the values of variables A and B are loaded into registers before the ALU performs the addition. Some instruction set architectures also allow certain instructions to use memory operands. Registers nevertheless play a crucial role in CPU performance.
There are many types of registers. The following sections introduce some representative examples.
General-Purpose Registers
General-purpose registers temporarily store data and addresses used in calculations.
For an addition instruction, for example, two values are loaded into general-purpose registers and the ALU performs the calculation using those values. The result is also stored in a general-purpose register and used by subsequent instructions.
Program Counter
The Program Counter is a register that holds the address of the next instruction to execute.
The CPU uses the Program Counter to determine where to fetch the next instruction. It normally advances to the following instruction, while branches, jumps, and exceptions can redirect execution to another address.
Stack Pointer
The Stack Pointer is a register that holds the current position at the top of the stack.
The stack is used for function calls and returns, storing local variables, and related operations. The CPU saves and restores the required data while updating the Stack Pointer.
Flags Register
On architectures such as x86, the Flags Register records status information produced by certain operations.
For example, it can indicate whether a result was zero, whether a carry occurred, or how two values compared.
The CPU uses this information to execute conditional branches corresponding to constructs such as if statements and for loops.
Registers Are Essential to CPU Processing
Although registers have very little capacity, their location inside the CPU makes them faster to access than memory.
The CPU uses registers every time it executes an instruction. Different registers—including the Program Counter, Stack Pointer, and Flags Register—divide responsibilities so that programs can execute efficiently.
The next section examines the ALU (Arithmetic Logic Unit), which performs the CPU’s calculations and comparisons.
The ALU and Control Unit
As explained above, the CPU repeatedly fetches, decodes, and executes instructions.
At the center of this processing are the Control Unit and the ALU (Arithmetic Logic Unit).
The Role of the Control Unit
The Control Unit manages the CPU’s overall operation. When the CPU fetches an instruction, the Control Unit decodes it and determines which operation must be performed.
For an addition instruction, for example, it directs the ALU to perform the calculation. For an instruction that loads data from memory, it controls memory access. For a conditional branch, it updates the Program Counter to change the next instruction to execute.
In this way, the Control Unit directs each circuit inside the CPU and ensures that instructions execute in the correct sequence.
The Role of the ALU
The ALU is the circuitry inside the CPU that performs calculations and comparisons. It handles operations such as the following.
• Addition and subtraction
• Greater-than and less-than comparisons
• Logical operations such as AND, OR, and XOR
• Bit shifts
When the CPU executes instructions such as “calculate 1 + 2” or “compare two values,” the ALU performs the actual calculation.
The Control Unit and ALU Work Together
The Control Unit and ALU do not operate independently. To execute an instruction such as “add A and B,” the Control Unit first decodes the instruction and directs the ALU to perform addition. The ALU carries out the calculation, and the result is stored in a register for use by the next instruction.
For an instruction such as “compare A and B,” the ALU performs the comparison and records the result in the Flags Register. The Control Unit refers to that result and performs a conditional branch when required.
The CPU can execute a wide variety of instructions because the Control Unit manages the overall operation while the ALU performs the actual calculations.

Division of Responsibilities Enables High-Speed Processing Inside the CPU
Although the CPU appears to be a single device, its Control Unit, ALU, registers, and other components work together while dividing responsibilities.
By coordinating at high speed, these circuits enable the CPU to execute an enormous number of instructions per second and support the many programs that run on Linux.
How This Relates to Linux
The CPU executes application and kernel instructions, while the Linux kernel decides which process or thread can use a CPU through scheduling.
When Linux switches from one task to another, it saves and restores CPU state—including register values—so that each task can later resume execution. This operation is called a context switch.
Understanding instructions and registers therefore provides a foundation for learning how the Linux scheduler and context switches work.
Conclusion
The CPU runs programs by repeatedly fetching the instructions that make them up, decoding those instructions, and executing them.
This article introduced the roles of Fetch, Decode, Execute, and Load/Store as the basic sequence through which the CPU executes instructions.
Many different components inside the CPU participate in instruction execution.
- Registers temporarily hold values, addresses, and other information used in calculations
- The Program Counter identifies the location of the next instruction to execute
- The Control Unit decodes instructions and directs the CPU’s internal circuitry
- The ALU performs addition, comparisons, logical operations, and similar work
In this way, multiple functions inside the CPU cooperate to process program instructions.
Real CPUs use more complex mechanisms—including pipelines, caches, and out-of-order execution—to accelerate processing. To understand basic CPU operation, however, it is essential to first grasp the sequence of fetching, decoding, and executing instructions.


コメント