Processor Organization, General Registers & Addressing Modes
Detailed study of CPU register sets, ALU bus interconnections, stack pointer mechanics, and fundamental addressing modes (Immediate, Direct, Indirect, Register Indirect, Indexed, Relative).
Learning Objectives
- •Trace register state changes during instruction fetch and decode cycles.
- •Differentiate between Zero-address, One-address, and Two-address machine architectures.
- •Calculate Effective Addresses (EA) for all standard addressing modes.
- •Implement and trace stack PUSH and POP pointer modifications in C.
Essential Prerequisites
- •Basic memory concept and byte pointers
- •Binary instruction opcode structure
Processor Registers, Stack aur Addressing Modes ka Funda
Addressing mode ka matlab bas itna hai ki CPU instruction ko ye kaise pata chalega ki operand (data) kahan rakha hua hai. Kya data seedhe instruction ke andar likha hai (Immediate mode)? Kya kisi register mein hai (Register mode)? Ya RAM ke kisi address pe chupa hua hai (Direct/Indirect mode)? Program Counter (PC), Accumulator (AC), aur Memory Address Register (MAR) sab milkar step-by-step memory se data nikaalte hain.
Imagine karo pizza delivery: Immediate mode = Pizza already tumhare haath mein hai. Direct mode = Delivery wale ko seedhe tumhara house number pata hai. Indirect mode = Delivery wala pehle tumhare guard ke paas jaata hai, guard diary khol kar tumhara flat number batata hai (Pointer to pointer).
Effective Address (EA) calculate karne ka numerical pakka aata hai! Bas ye table ratt lo: Immediate: No EA. Direct: EA = Address field. Indirect: EA = M[Address field]. Indexed: EA = Address + Index Register. Relative: EA = PC + Offset.
Puchte hain: 'Why do we need Indexed addressing in modern OS?' Seedha bolo: 'Arrays aur data buffers ko loop mein access karne ke liye Indexed mode use hota hai, jahan base address fixed rehta hai aur index register loop ke counter ke saath increment hota hai.'
The Core Mental Model
Why This Exists
Compilers convert high-level programming constructs (like array lookups `arr[i]`, pointer dereferencing `*ptr`, and local function calls) directly into specific CPU addressing modes. Understanding these modes is necessary to write optimized C/C++ systems code and understand assembly disassembly.
Beginner Foundation
When the processor executes an instruction like ADD, it needs operands. Does the instruction bring the number itself? Or does it tell the CPU which register or RAM address to check? The addressing mode defines the rule for locating the target number.
Micro Concepts Decomposition
Internal Processor Organization & Register Sets
The CPU comprises Program Counter (PC), Instruction Register (IR), Memory Address Register (MAR), Memory Data Register (MDR), Accumulator (AC), and General Purpose Registers (R0-R7). Internal buses route data between registers and ALU multiplexers.
Stack Organization: Register Stack vs Memory Stack
A Stack is a LIFO (Last-In-First-Out) storage structure managed by a Stack Pointer (SP). A Register Stack uses dedicated internal flip-flops with bounded depth; a Memory Stack reserves a partition of RAM where SP decrements on PUSH and increments on POP (in typical descending stack architectures).
Immediate, Direct, and Indirect Addressing Modes
Immediate: Operand is part of instruction (EA = None, value = field). Direct: Effective Address (EA) = Address Field. Indirect: Address field points to memory location containing the effective address (EA = M[Address Field]), requiring two memory accesses.
Displacement Addressing: Relative, Base-Register, and Indexed
Relative: EA = PC + Address Offset (used for conditional branch jumps). Base-Register: EA = Base Register + Offset (used for relocatable code in OS). Indexed: EA = Index Register + Offset (used for array traversal where index register increments in loops).
Hardware State Machine Architecture
Interactive Simulator
5-Stage Pipeline Hazard & Forwarding Unit Laboratory
| Instruction | T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10 | T11 | T12 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
ADD R1, R2, R3IF | IF | ID | EX | MEM | WB | · | · | · | · | · | · | · |
SUB R4, R1, R5 | · | IF | ID | EX | MEM | WB | · | · | · | · | · | · |
AND R6, R1, R7 | · | · | IF | STALL | ID | EX | MEM | WB | · | · | · | · |
OR R8, R4, R1 | · | · | · | IF | STALL | ID | EX | MEM | WB | · | · | · |
LW R9, 0(R8) | · | · | · | · | IF | ID | EX | MEM | WB | · | · | · |
ADD R10, R9, R2 | · | · | · | · | · | IF | ID | EX | MEM | WB | · | · |
Forwarding Unit ACTIVE: Data hazards between consecutive ALU instructions (e.g. R1 written by ADD and read by SUB) are resolved without any stalls by forwarding the ALU output from EX/MEM latch directly into the ALU input multiplexer! Notice how instruction 6 (ADD R10, R9, R2) still requires 1 stall bubble because Load-Use hazard data is only ready after the MEM stage.
End-to-End Execution Trace
Step-by-Step Code Execution (C)
Sandbox Terminal Ready
Click Run Code or press Ctrl+Enter to compile and execute.
Where Students Lose Marks
Active Assessment Quiz
No Practice Questions Configured
Questions for this topic are currently undergoing faculty review.