CPU
CPU
CPU: The CPU, or Central Processing Unit, is the main part of a computer that does most of the work. It's
often called the "brain" of the computer.
Electronic circuitry: This means the arrangement of electronic parts (like transistors and circuits) inside the
CPU that allows it to perform tasks.
Specified by the instructions in the program: The CPU follows a set of instructions from the program
(software) to know what to do step by step.
In simple terms: The CPU is the part of the computer that does the main work by following instructions given
by the program. It performs calculations, makes decisions, and controls data flow in the computer.
Components of the CPU
1. Registers:
o Definition: Registers are small, fast storage areas within the CPU.
o Purpose: They temporarily hold data and instructions that the CPU is currently working on or will process next.
o Key Feature: Registers operate at very high speeds to keep up with the CPU's processing speed, making it quicker for the CPU
to access data than if it were stored in regular memory (like RAM).
2. Arithmetic Logic Unit (ALU):
o Definition: The ALU is the part of the CPU that handles all arithmetic (math) and logic (decision-making) operations.
o Functions:
Arithmetic operations: These include basic math functions like addition and multiplication.
Logic operations: These involve comparing values, such as checking if one number is equal to, greater than, or less
than another (AND, OR, etc.).
o How it works: The ALU takes numbers stored in registers, performs the needed calculations or comparisons, and then sends the
results back to registers.
3. Control Unit:
o Definition: The control unit is like the “manager” of the CPU.
o Purpose: It directs the operations of the CPU, telling other parts (like the ALU and registers) what to do, when to do it, and in
what order.
o Function: The control unit sends signals to other parts of the CPU, ensuring everything works in sync and that instructions are
followed in the correct order.
Registers, ALU, and Control Unit are all inside the CPU.
Memory (RAM): The CPU connects to RAM (Random Access Memory), which stores the program instructions and data that the CPU
will use. RAM is larger than registers but slower.
Input/Output (I/O) Controllers: These connect the CPU to devices like a hard drive, mouse, keyboard, network modem, and other
external components.
o The I/O controllers act as a bridge, allowing the CPU to send and receive data to and from these devices.
In summary:
This structure allows the CPU to process data, perform tasks, and interact with other parts of the computer.
Microprocessor
Back in the old days, a CPU (Central Processing Unit) was made up of many separate electronic chips
connected together. For example:
Registers (temporary storage areas) might have been on one or more chips.
The Arithmetic Logic Unit (ALU) might have been on a separate chip.
In other words, different parts of the CPU were on different chips, so they had to be connected to work together.
Nowadays, all CPUs are microprocessors, meaning they all fit on a single chip.
When we say "64-bit x86 CPUs with up to 18 cores," it refers to several key characteristics of the CPU:
1. 64-bit:
o The CPU can handle 64 bits (or binary digits) of data at once.---Q
o This means it can process larger chunks of data and access a larger memory space compared to
32-bit CPUs.
o A 64-bit CPU is capable of running both 32-bit and 64-bit software, while a 32-bit CPU can only
handle 32-bit software.
2. x86:
o This refers to the CPU architecture, a type of design and instruction set created by Intel.
o The "x86" architecture is widely used in personal computers and servers.
o Modern "x86" CPUs often use an extension called "x86-64," which allows them to be 64-bit
processors.
3. Up to 18 Cores:
o A core is like a mini-CPU within the main CPU. Each core can handle its own tasks
independently.
o Having 18 cores means the CPU can handle 18 different tasks simultaneously.
o This improves performance for multitasking and for applications that need a lot of processing
power, like video editing, 3D rendering, or running multiple programs at once.
In summary, a 64-bit x86 CPU with up to 18 cores is a powerful processor that can handle complex tasks, run
both 32-bit and 64-bit applications, and efficiently manage multiple tasks at the same time due to its multi-core
design.
This picture provides an overview of the Intel 8086 microprocessor and some of its key specifications:
The pin diagram shows the layout of the 40-pin 8086 chip. Each pin has a specific function, like transferring
data or addressing memory. The 8086 has two operating modes, Max Mode and Min Mode, which dictate how
it interacts with other processors and components.
Registers are small, high-speed memory slots built right into the CPU. They serve as temporary storage
locations for data or addresses that the CPU is actively using. Since they are on the CPU itself, accessing
Purpose: Registers hold data or memory addresses while instructions are being executed. For instance,
they may store intermediate results from calculations or the address of data in RAM.
Number and Size: The quantity and bit capacity of registers differ across CPUs. The size of a register
(like 8-bit, 16-bit, etc.) defines the maximum number of bits it can hold. For example, a 16-bit register
can store data values up to 2^16 - 1. CPUs with larger registers can handle more data at once, making
Not in Main Memory: Registers are not part of the main memory (RAM). Instead, they are integrated
within the CPU, making them faster to access but limited in storage capacity.
In summary, registers are essential for quick data access and manipulation within the CPU, significantly
speeding up processing by minimizing the need to access slower memory types like RAM.
Size: Registers come in different sizes (4 bits, 8 bits, 16 bits, etc.), which defines how much data they can
hold at once.
ARM architecture: In ARM processors (like in iPhones), there are 31 general-purpose 64-bit registers (for
general tasks) and 32 special 128-bit registers for handling floating-point calculations.
In modern processors: Both the size and number of registers are increasing to handle more complex tasks
efficiently.
Register types: Registers are generally divided into general-purpose (for various tasks) and special-purpose
(for specific functions) types.
Addressing registers by name: Since there are limited registers, they are usually referenced by specific
names (like AX, EAX) in assembly language instead of memory addresses.
Naming conventions: Register names vary by processor type and typically use uppercase letters and
combinations like A, AX, EAX to identify them.
Scratch paper analogy: Registers act as temporary storage (scratch paper) for quick calculations and data
manipulation, holding data currently being processed.
Function parameters and return values: Registers often store input values for functions and return results
after computations.
Processor instructions: Most processor instructions involve moving data in and out of registers and
performing calculations directly on this data, as this is the foundation of program execution at a low level.
1. General Purpose Registers: These store data for the Arithmetic Logic Unit (ALU) to use in
calculations and can hold intermediate or final results from these operations.
2. Special Purpose Registers: These have specific functions, including:
o Instruction Address Register: Holds the memory location where the next instruction is located,
as managed by the operating system.
o Data Address Register: Holds the memory location where data is stored.
o Special Address Register: Holds memory addresses used for unique or special functions.
o Instruction Register: Contains the machine code (binary) of the current instruction being
executed.
o Status Register: Stores the current status or state of the CPU, such as whether it is busy or
ready.
These registers help manage data flow, control processes, and track the CPU's operational state.
Program Counter (PC): This register keeps track of the address in memory where the next instruction is
stored. After each instruction, it moves to the next memory address, guiding the CPU on what to execute next.
1. Memory Address Register (MAR): The MAR holds the memory address for either:
o The current instruction being fetched, or
o The location where data should be transferred (read from or written to memory).
2. Memory Data Register (MDR): This register temporarily stores data:
o That was fetched from the memory address in the MAR, or
o That is about to be transferred to a specific memory address.
3. Instruction Register (IR): The Instruction Register (IR) is where the CPU places an instruction after fetching
it from memory. Once the instruction is in the IR, the CPU decodes it to understand what action to perform (like
addition, data movement, etc.). After decoding, the CPU executes the instruction, carrying out the action
specified. Essentially, the IR temporarily holds the instruction while the CPU figures out and performs the
necessary operation.
4. Accumulator (ACC): The ACC is a special register that the ALU (Arithmetic Logic Unit) uses to hold
data while performing calculations. It temporarily stores results, making it easier for the CPU to process
continuous operations.
Each of these registers has a specific role in the CPU's process of fetching, decoding, and executing instructions.
This diagram depicts the architecture of a basic Central Processing Unit (CPU) and its interaction with memory. Here's a breakdown:
CPU Components:
General Registers (R0-R3): These are temporary storage locations used to hold data during program execution.
ALU (Arithmetic Logic Unit): Performs arithmetic and logical operations on data from registers.
Input Register 1 & 2: Registers used to temporarily hold data being fetched from memory.
Output Register: Holds results from the ALU before being sent to memory.
Program Counter: Keeps track of the address of the next instruction to be executed.
Instruction Register: Holds the current instruction being processed.
Instruction Decoder: Decodes the current instruction and generates control signals for other components.
Control Unit: Generates control signals to coordinate all CPU operations.
Memory Components:
1. Fetch: The Program Counter holds the address of the next instruction in memory. The CPU sends this address on the Address Bus to
memory.
2. Decode: The instruction is fetched from memory and placed in the Instruction Register. The Instruction Decoder interprets the
instruction and generates control signals.
3. Execute: The CPU executes the instruction. This may involve using the ALU, loading/storing data from registers, or accessing data in
memory.
4. Store: Results of operations are stored in registers or back to memory.
This cycle repeats continuously, executing the program instructions one after another. The control signals generated by the CPU
determine the overall operation and flow of data through the system.
Let's imagine we want the CPU to add two numbers stored in memory at specific addresses: 1001 and 1002.
The addition instruction is at memory address 1000.
Step-by-Step Process:
This sequence allows the CPU to complete instructions, one at a time, using registers and control units to
manage data and operations efficiently. The CPU continuously fetches, decodes, executes, and stores results,
moving seamlessly from one instruction to the next.
---------------------------------------------------------------------------------------------------------------------------------------
1. General Registers (R0, R1, R2, R3):
o These are small, fast storage locations in the CPU.
o Programmers use these registers to store temporary data while the program runs, which helps the
CPU process faster.
o Each register is 16 bits in size, meaning it can store numbers up to 16 bits long, matching the
memory size in TOY1.
2. Buses (Communication Paths):
o Buses are like highways in the CPU for transferring data and instructions within the CPU and
between the CPU and memory.
o There are three main buses:
Address Bus: Carries memory addresses from the CPU to memory, telling it where to
read or write data. This bus is one-way (CPU to memory).
Data Bus: Transfers actual data between the CPU and memory. It’s bi-directional,
meaning it can go both ways (CPU to memory or memory to CPU).
Control Bus: Sends commands to memory, like whether the CPU wants to read data or
write data.
3. TOY1 Bus Sizes:
o Address Bus: 10 bits wide, so it can handle addresses up to 10 bits long.
o Data Bus: 16 bits wide, matching the size of each memory location.
o Control Bus: 1 bit wide, to signal a read or write operation.
4. Extra Registers (MAR and MDR):
o Memory Address Register (MAR): Temporarily holds the address of the data to be accessed.
o Memory Data Register (MDR): Temporarily holds the data itself, either being written to or
read from memory.
These components work together to efficiently move data and instructions across the CPU and memory, making
program execution faster and smoother.
This image illustrates the registers in the Intel Core i7 processor, released in 2009. The table shows the 64-bit
registers, along with the 32-bit registers that make up the lower half of the 64-bit registers, the 16-bit registers
that form the lower half of the 32-bit registers, and the 8-bit registers that form the lower half of the 16-bit
registers.
Key registers in the processor include:
The table also shows naming conventions for each register. The "r" prefix indicates a general-purpose register,
while suffixes represent register sizes: "d" for 32-bit, "w" for 16-bit, and "b" for 8-bit. For example, rax is a
64-bit register, eax refers to its lower 32 bits, ax to its lower 16 bits, and al to its lower 8 bits.This visual
overview of Intel Core i7 registers and naming conventions aids programmers in understanding the processor’s
memory architecture and effectively using these registers in their programs.
Another diagram of the Intel 8086 microprocessor's registers. The diagram shows the different types of
registers: general purpose, pointer and index, segment, and flags. Each register has a specific purpose. For
example, the accumulator is used for arithmetic operations, the stack pointer keeps track of the stack, and the
flags are used to store the results of conditional operations.
Summarry of Registers
In a CPU, registers are small storage units that temporarily hold data, instructions, or addresses. They help the
CPU work faster by keeping essential information close by, so it doesn’t have to repeatedly access slower
memory. Here’s an overview of the main types of registers and what they do:
1. General-Purpose Registers
o Purpose: These are flexible registers used to store temporary data, results from calculations, or values
needed during program execution.
o Examples: Common names for these registers are R0, R1, AX, EAX, or RAX depending on the processor
type. For example, RAX can store a return value from a function.
2. Special-Purpose Registers
o Purpose: These registers are used for specific control and memory-related tasks within the CPU. They
ensure the CPU knows where to find data and instructions and manage the flow of information.
o Examples of Special-Purpose Registers:
Program Counter (PC): Holds the address of the next instruction the CPU needs to fetch and
execute.
Instruction Register (IR): Stores the current instruction being processed by the CPU.
Memory Address Register (MAR): Contains the memory address of data the CPU needs to
access.
Memory Data Register (MDR): Temporarily holds data either fetched from memory or waiting
to be written to memory.
Status Register (Flags Register): Holds flags or status indicators, like whether a calculation
resulted in zero, if there was a carry-over, or if an error occurred.
4. Floating-Point Registers
o Purpose: These registers handle decimal (floating-point) numbers, which are used in complex
calculations requiring high precision.
o Example: In scientific calculations involving decimals, floating-point registers store numbers like
3.14159.
Each type of register plays a specific role to help the CPU quickly access and process information. General-
purpose registers handle varied tasks, while special-purpose registers keep track of instructions and memory
locations. Together, they enable efficient and organized processing within the CPU.
This image illustrates the core structure of an Arithmetic Logic Unit (ALU) and how it functions within a
Pentium processor.
ALU Structure
Components: The ALU includes an adder, a shift register, carry/rotate logic, and a control unit.
Function: It performs basic arithmetic (like addition and subtraction) and logical operations (like shifting and
rotating) on binary data.
Inputs: The ALU takes two operands (A and B), a carry-in bit (Cin), and control signals to direct the operation.
Outputs: It generates the operation result and a carry-out bit (Cout) for certain operations.
Multiple ALUs: The Pentium processor has several ALUs for fast, efficient processing.
Dedicated ALUs: Separate ALUs handle integer calculations, floating-point calculations, and operations like
multiplication and division.
Cache and Pipelines: The processor uses caches (for code and data) to speed up data access, and pipelines to
handle multiple tasks simultaneously.
Bus Interface: A 64-bit bus interface connects the ALU with other processor components for data transfer.
Summary
This image offers a simplified view of a basic ALU, showing its main components and their roles in performing
arithmetic and logical operations. In the Pentium processor, multiple ALUs work together to boost processing
power, aided by caching, pipelining, and an efficient bus interface.
Function: The Control Unit (CU) is a crucial part of the CPU that directs how the computer operates.
Role: It manages the flow of instructions, ensuring that different components (like memory and the Arithmetic Logic
Unit) work together at the right time.
Operation:
Instruction Handling: The CU fetches instructions from memory and decodes them to determine the next steps.
Coordination: It activates the necessary parts of the CPU and other devices to perform tasks in the correct order.
In summary, the CU acts like a manager, ensuring all parts of the computer work together smoothly to follow
instructions.
The image shows the different stages of the CPU's instruction cycle, which is the basic process that CPUs use to execute
instructions. The cycle has four main stages:
Decode: The CPU decodes the instruction, which means it figures out what the instruction means.
Execute: The CPU executes the instruction, which means it performs the actions specified by the instruction.
Store: The CPU stores the results of the execution, either in a temporary storage location (a register) or in memory.
The image shows these four stages with different colors and arrows showing the flow of the cycle. The arrows indicate
the different steps of the CPU's processing:
This cycle repeats continuously, allowing the CPU to execute programs and perform tasks.
Fetch: The CPU retrieves the instruction from memory, which might look something like "ADD 10, 5".
Decode: The CPU interprets this instruction as meaning "add the number 10 to the number 5".
Execute: The CPU performs the addition operation, calculating the sum of 10 and 5, which is 15.
Store: The CPU stores the result (15) in a temporary location or in memory, where it can be used later by the program.
The CPU then repeats this cycle for every instruction in the program, processing each one step by step. This is how the
CPU carries out the instructions of a program, enabling it to perform tasks such as calculations, data manipulation, and
output.
The Fetch-Decode-Execute-Store cycle is a fundamental process in computer architecture that explains how a CPU
executes instructions. Here's a breakdown of each step:
Fetch: The CPU retrieves the next instruction from main memory and places it in the Instruction Register. This is like
picking up a recipe from the cookbook.
Decode: The Control Unit, a part of the CPU, analyzes the instruction to understand its purpose and the data it needs to
work with. This is like reading the recipe and identifying the ingredients and cooking steps.
Execute: The CPU performs the operations specified by the instruction, using the data from the registers. This is like
following the recipe and preparing the dish.
Store: The result of the executed instruction is stored back into a register or memory location. This is like putting the
finished dish on the table.
This cycle repeats continuously, allowing the CPU to process a stream of instructions and perform tasks.
How the CPU runs a program to add two numbers, using a simple example. We'll say we want to add the
numbers 5 and 3.
Example Program
Let's say our program has the following instructions in memory:
Step-by-Step Process
Next Instructions
Following the same process:
Final Step
• The CPU will continue this process for any remaining instructions in the program, but for this example, we
have successfully added 5 and 3, and the result (8) is now stored in register C.
Summary
In summary, the CPU runs the program by fetching, decoding, and executing each instruction in a loop. In this
case, it added two numbers (5 and 3) and stored the result (8) in a register.