🖥️ BCA 1st Semester - Computer System
Architecture
📚 UNIT – 5: Central Processing Unit (CPU)
🔧 Central Processing Unit (CPU)
The Central Processing Unit (CPU) is the primary component of a computer
that performs most of the processing inside the computer. It is often called
the "brain" of the computer system. The CPU executes instructions from
computer programs by performing basic arithmetic, logical, control, and
input/output operations.
🎯 Key Functions of CPU:
Instruction Processing: Fetching, decoding, and executing
instructions
Data Manipulation: Performing arithmetic and logical operations
Control Operations: Managing the flow of data and instructions
Memory Management: Coordinating with memory systems
📋 Register Organization
Registers are high-speed storage locations within the CPU that temporarily
hold data and instructions during processing. They are the fastest form of
computer data storage.
🔍 Types of Registers:
🎪 General Purpose Registers
Used for storing temporary data and intermediate results
Can be used for various purposes as needed by the program
Typically 8, 16, 32, or 64 bits in size
Examples: AX, BX, CX, DX in x86 architecture
🎯 Special Purpose Registers
📍 Program Counter (PC)
Contains the address of the next instruction to be executed
Automatically incremented after each instruction fetch
Also known as Instruction Pointer (IP)
📦 Instruction Register (IR)
Holds the current instruction being executed
Loaded during the fetch phase of instruction cycle
Contains the complete instruction including opcode and operands
🏠 Memory Address Register (MAR)
Contains the address of memory location to be accessed
Used for both read and write operations
Connects CPU to memory system
📊 Memory Data Register (MDR)
Contains data being transferred to or from memory
Also called Memory Buffer Register (MBR)
Acts as a buffer between CPU and memory
🚩 Status Register (Flag Register)
Contains condition codes and status flags
Examples: Zero flag, Carry flag, Overflow flag, Sign flag
Used for conditional branching and program control
📚 Stack Pointer (SP)
Points to the top of the current stack
Used for stack operations (push and pop)
Essential for function calls and local variable storage
🔗 Base Register
Used in addressing modes for calculating effective addresses
Helps in memory segmentation and relocation
📏 Index Register
Used for array indexing and address modification
Often used in loop operations and array processing
📝 Instruction Formats and Types
Instructions are the basic commands that the CPU can execute. The format
of an instruction defines how it is structured and organized in memory.
🏗️ Instruction Format Components:
🎭 Opcode (Operation Code)
Specifies the operation to be performed
Examples: ADD, SUB, MOV, JMP
Determines the type of instruction and required operands
🎪 Operand Fields
Specify the data or addresses on which the operation is performed
Can be immediate values, register references, or memory addresses
Number of operands varies by instruction type
📊 Types of Instruction Formats:
🔢 Zero Address Instructions
No explicit operands in the instruction
Uses stack-based operations
Example: Stack machines, calculators
Format: OPCODE
1️⃣ One Address Instructions
Single operand specified
Often uses accumulator as implicit second operand
Format: OPCODE OPERAND
Example: LOAD A (load A into accumulator)
2️⃣ Two Address Instructions
Two operands specified
One operand often serves as both source and destination
Format: OPCODE DEST, SRC
Example: ADD R1, R2 (R1 = R1 + R2)
3️⃣ Three Address Instructions
Three operands specified
Two sources and one destination
Format: OPCODE DEST, SRC1, SRC2
Example: ADD R1, R2, R3 (R1 = R2 + R3)
🎨 Types of Instructions:
🧮 Arithmetic Instructions
Perform mathematical operations
Examples: ADD, SUB, MUL, DIV
Work with integer and floating-point numbers
Set flags based on results
🔗 Logical Instructions
Perform boolean operations
Examples: AND, OR, NOT, XOR
Used for bit manipulation and masking
Essential for decision making
📦 Data Transfer Instructions
Move data between locations
Examples: MOV, LOAD, STORE
Transfer between registers, memory, and I/O devices
Most frequently used instruction type
🔄 Control Transfer Instructions
Alter the sequence of program execution
Examples: JMP, CALL, RET, conditional jumps
Enable loops, function calls, and conditional execution
Critical for program flow control
🔧 I/O Instructions
Handle input and output operations
Examples: IN, OUT
Transfer data between CPU and peripheral devices
May be privileged instructions in some systems
🎯 Addressing Modes
Addressing modes specify how the operand of an instruction is located in
memory or registers. They determine how the CPU calculates the effective
address of an operand.
📍 Types of Addressing Modes:
🎪 Immediate Addressing
Operand is part of the instruction itself
No memory access required for operand
Fastest addressing mode
Example: MOV R1, #5 (move immediate value 5 to R1)
Advantages: Fast execution, no additional memory access
Disadvantages: Limited range of values
📝 Direct Addressing
Instruction contains the actual address of operand
Single memory access required
Simple and straightforward
Example: MOV R1, 1000 (move contents of address 1000 to R1)
Advantages: Simple implementation
Disadvantages: Limited address space
🔗 Indirect Addressing
Instruction contains address of address (pointer)
Two memory accesses required
Flexible for dynamic addressing
Example: MOV R1, @1000 (move contents of address pointed by 1000)
Advantages: Extended address space, dynamic addressing
Disadvantages: Slower due to multiple memory accesses
📋 Register Addressing
Operand is in a specified register
No memory access for operand
Very fast execution
Example: MOV R1, R2 (move contents of R2 to R1)
Advantages: Fastest execution
Disadvantages: Limited number of registers
📊 Register Indirect Addressing
Register contains the address of operand
One memory access required
Combines speed of registers with memory flexibility
Example: MOV R1, (R2) (move contents of address in R2 to R1)
🏠 Base + Displacement Addressing
Effective address = Base register + Displacement
Used for accessing data structures
Example: MOV R1, 10(R2) (move contents of address R2+10 to R1)
Applications: Array access, structure member access
📏 Indexed Addressing
Effective address = Index register + Address field
Useful for array processing
Example: MOV R1, Array(R2) (R2 contains index)
Applications: Loop processing, array operations
🔄 Relative Addressing
Effective address = Program Counter + Displacement
Used for branch instructions
Position-independent code
Example: JMP +5 (jump 5 instructions ahead)
🔄 Introduction to Instruction Cycle
The instruction cycle is the basic operational process of a CPU. It describes
the sequence of actions that the CPU performs to execute each instruction.
🎯 Phases of Instruction Cycle:
1️⃣ Fetch Phase
Purpose: Retrieve the next instruction from memory
Steps:
Send PC contents to MAR
Send read signal to memory
Transfer instruction from memory to MDR
Copy instruction from MDR to IR
Increment PC to point to next instruction
2️⃣ Decode Phase
Purpose: Interpret the fetched instruction
Steps:
Analyze opcode to determine operation type
Identify required operands and their locations
Determine addressing modes
Prepare control signals for execution
3️⃣ Execute Phase
Purpose: Perform the specified operation
Steps:
Fetch operands if necessary
Perform the operation (arithmetic, logical, etc.)
Store results in appropriate location
Update flags and registers as needed
🔄 Instruction Cycle Flow:
START → FETCH → DECODE → EXECUTE → CHECK INTERRUPT → FETCH (next
instruction)
⚡ Factors Affecting Instruction Cycle:
🎪 Instruction Complexity
Simple instructions execute faster
Complex instructions may require multiple cycles
RISC vs CISC architecture differences
🧠 Memory Speed
Faster memory reduces fetch time
Cache memory improves performance
Memory hierarchy impact
🔧 CPU Clock Speed
Higher frequency enables faster processing
Measured in Hertz (Hz)
Affects all phases of instruction cycle
🎛️ Control Unit – Hardwired vs Microprogrammed
Control
The Control Unit (CU) is responsible for directing the operation of the
processor. It generates control signals that coordinate the activities of
other CPU components.
🔧 Functions of Control Unit:
Instruction fetching and decoding
Generating control signals
Coordinating data flow
Managing instruction sequencing
Handling interrupts and exceptions
⚡ Hardwired Control
Hardwired control uses dedicated hardware circuits to generate control
signals. The control logic is implemented using combinational and
sequential logic circuits.
🎯 Characteristics:
Fast Operation: Direct hardware implementation provides high speed
Fixed Control Logic: Control sequences are permanently wired
Complex Design: Requires extensive logic circuits
Difficult Modification: Changes require hardware redesign
🏗️ Implementation:
Uses logic gates, flip-flops, and decoders
State machines control instruction execution
Separate circuits for each instruction type
Timing signals coordinate operations
✅ Advantages:
High Speed: Fastest control method available
Optimal Performance: No interpretation overhead
Reliable Operation: Less prone to software errors
Predictable Timing: Fixed execution times
❌ Disadvantages:
Design Complexity: Complex circuit design required
Inflexibility: Difficult to modify or extend
High Cost: Expensive to implement and modify
Limited Instruction Set: Constrained by hardware
🎪 Applications:
High-performance processors
Embedded systems requiring speed
Simple instruction set computers (RISC)
Real-time systems
🧠 Microprogrammed Control
Microprogrammed control uses stored programs (microprograms) to
generate control signals. Control sequences are stored in a special memory
called control memory.
🎯 Characteristics:
Flexible Control: Easy to modify control sequences
Software-Based: Control logic implemented as programs
Slower Operation: Requires microinstruction fetching
Complex Instruction Support: Can implement complex operations
🏗️ Implementation:
Control Memory: Stores microprograms
Microinstruction Register: Holds current microinstruction
Sequencing Logic: Determines next microinstruction
Address Generation: Controls microprogram flow
📊 Microinstruction Format:
Control Fields: Specify control signals to activate
Next Address Field: Points to next microinstruction
Condition Fields: Enable conditional branching
Timing Fields: Control signal timing
✅ Advantages:
Flexibility: Easy to modify and extend
Complex Instructions: Can implement sophisticated operations
Easier Design: Systematic design approach
Debugging Support: Can trace microprogram execution
❌ Disadvantages:
Slower Speed: Additional memory access overhead
Memory Requirements: Needs control memory space
Interpretation Overhead: Must decode microinstructions
Design Complexity: Requires microprogram development
🎪 Applications:
Complex instruction set computers (CISC)
Processors with extensive instruction sets
Systems requiring frequent updates
Educational and research processors
🔄 Comparison: Hardwired vs Microprogrammed
Aspect 🔧 Hardwired 🧠 Microprogrammed
Speed Very Fast Moderate
Flexibility Low High
Cost High Initial Lower Initial
Complexity High Design Moderate Design
Modification Difficult Easy
Memory Usage None Extra Control Memory
Debugging Difficult Easier
Instruction Set Simple Complex
🎯 Choosing the Right Approach:
🔧 Choose Hardwired When:
Speed is critical requirement
Instruction set is simple and stable
Cost is not primary concern
Real-time performance needed
🧠 Choose Microprogrammed When:
Flexibility is important
Complex instruction set required
Frequent modifications expected
Development time is limited
🎯 Summary
The Central Processing Unit (CPU) is the core component that executes
instructions and controls computer operations. Understanding CPU
architecture involves:
Register Organization: Various types of registers for data storage and
control
Instruction Formats: Different ways to structure and organize
instructions
Addressing Modes: Methods for locating operands in memory and
registers
Instruction Cycle: The fetch-decode-execute sequence that processes
instructions
Control Unit Design: Hardwired vs microprogrammed approaches for
instruction control
Each aspect plays a crucial role in determining the performance, flexibility,
and capabilities of the computer system. Modern processors often
combine elements from both hardwired and microprogrammed
approaches to achieve optimal performance and flexibility.
🎓 Learning Objectives Achieved:
✅ Understanding CPU components and their functions
✅ Knowledge of register types and their purposes
✅ Comprehension of instruction formats and addressing modes
✅ Familiarity with instruction cycle phases
✅ Comparison of control unit design approaches
End of Unit 5: Central Processing Unit (CPU)