1.3 - The CPU & Fetch–Decode–Execute
What the CPU is and its role in a computer system
The Central Processing Unit (CPU) is the main part of a computer that carries out instructions from programs. It acts like the brain of the computer, processing data to make the system work.
The CPU takes input from devices, processes it according to instructions, and sends results to output devices. This processing involves performing calculations and controlling how data moves around the system.
The main components of the CPU
The CPU contains several key parts that work together to handle instructions and data. These components interact closely with each other and with the computer's memory.
Key components and their functions
- Control Unit (CU) - Directs the flow of data within the CPU and to other parts of the computer.
- Arithmetic Logic Unit (ALU) - Carries out mathematical calculations.
- Registers - Hold data and instructions that are ready to be used immediately by the CPU.
The CPU also connects to memory, which holds the program's instructions and data.
How data flows in and around the CPU
Data moves through the CPU in a structured way to ensure instructions are processed correctly. This flow involves input, processing, and output, with arrows representing the paths data can take.
The flow of data
- Data enters the CPU from input devices and goes to the registers.
- The CU directs data between the registers, ALU, and memory as needed.
- The ALU processes data from the registers, performing calculations.
- Processed data can be sent back to memory or to output devices via the CU.
- Memory provides instructions and data to the CPU, and receives updated data in return.
The fetch-decode-execute cycle
The CPU processes instructions using a repeating process called the fetch-decode-execute cycle. This cycle runs continuously while the computer is on, handling one instruction after another.
Stages of the fetch-decode-execute cycle
- Fetch - The CU retrieves the next instruction from memory and moves it to a register in the CPU.
- Decode - The CU analyses the instruction to understand what action is required.
- Execute - The instruction is carried out, for example, a calculation is performed.
After execution, the cycle loops back to fetch the next instruction. This happens billions of times per second.
Factors affecting CPU performance
The speed and efficiency of a CPU depend on its design features. These characteristics determine how quickly and effectively it can process instructions.
Key factors influencing performance
- Clock speed - This describes how fast the CPU can process instructions. A higher clock speed means instructions are processed more quickly, making the computer run faster overall.
- Number of cores - More cores allow the CPU to handle multiple instructions at the same time, which can make the computer run faster.