Addressing Modes
Definition: Addressing mode specifies how to interpret the operand in an instruction (where the operand is located or how to get it).
- Immediate Addressing Mode β
-
Operand is given directly in the instruction.
- Advantage: Fast, no memory access for operand.
- Application: Constants.
- Example:
MOV A, #5β Load 5 into A.
-
- Direct (Absolute) Addressing Mode β
-
Address field contains the actual memory address of the operand.
- Application: Access fixed memory location.
- Example:
MOV A, 2000Hβ Load from memory 2000H.
-
- Indirect Addressing Mode β
- Address field contains a register/memory location holding the effective address of the operand.
-
Application: Pointers, linked lists.
- Example:
MOV A, @R0β Effective address from R0.
- Register Addressing Mode
- Operand is in a CPU register.
- Application: Very fast access.
- Example:
MOV A, R1.
- Register Indirect Addressing Mode
- Register contains the address of operand in memory.
- Application: Table lookups.
- Example:
MOV A, @R2.
- Base Addressing Mode β
- Effective Address (EA) = Base Register + Displacement.
-
Application: Relocatable programs.
- Example:
MOV A, 1000(RB).
- Index Addressing Mode β
- EA = Index Register + Base Address.
- Application: Arrays.
- Example:
MOV A, ARR(RI).
- Relative Addressing Mode β
- EA = Program Counter (PC) + Displacement.
- Application: Branching instructions.
- Example:
BEQ LABEL.
- Autoincrement / Autodecrement Addressing
- Register points to operand and is incremented/decremented automatically after/before use.
- Application: Stack operations, sequential data.
- Example:
MOV A, (R1)+.
Quick Match for PSU-type Questions:
- Immediate β Constants
- Direct β Fixed data
- Indirect β Pointers
- Register β Fast data access
- Base β Relocatable programs
- Index β Arrays
- Relative β Branching
- Auto inc/dec β Stack or sequential access
Difference between Base, Index, and Relative Addressing Modes.
- Base Addressing
- Base β relocation flexibility.
-
Base comes from a base register that can be changed at runtime.
- Useful for relocatable programs: move the whole program in memory, just update the base register.
- Example: OS loads a process at a new memory location without changing its instructions.
- Index Addressing
- Index β array element access.
-
Base is a constant in the instruction (start of an array), displacement_ is an index register that changes.
- Perfect for arrays/tables: just increment the index register to access the next element.
- Example: Loop accessing array elements sequentially.
- Relative Addressing
- Relative β branching within a short distance.
-
Base is the PC, displacement_ is a constant offset in instruction.
- Used for branching/jumps: target is always relative to the current instruction, making code position-independent.
- Example:
BEQ LABELworks even if program is loaded at a different address.
| Mode | Base Source | Displacement Source | Main Use |
|---|---|---|---|
| Base Addressing | Base Register | Constant | Relocatable programs |
| Index Addressing | Constant (Base Address) | Index Register | Arrays, tables |
| Relative Addressing | Program Counter | Constant | Branching, position-independent code |
Types of Addressing Mode
Section titled βTypes of Addressing ModeβA. Non-Computable Addressing Modes
Effective address is obtained without arithmetic computation
-
Implied Mode: Operand is implicitly defined by opcode (no address field required).
- Immediate Mode: itself** (constant data).
-
Direct Mode: Address field contains the effective address (E.A) of operand. Operand = M[Address]
-
Indirect Mode: Address field points to a memory location that contains E.A. E.A = M[Address], Operand = M[E.A]
-
Register Mode: Address field specifies a register which contains operand. Operand = R
-
Register Indirect Mode: Address field specifies a register which contains E.A of operand. E.A = R, Operand = M[E.A]
B. Computable Addressing Modes
Effective address is computed using arithmetic like
+/-
- Autoincrement / Autodecrement Mode
Register indirect mode where register is automatically updated after/before access.Operand = M[R], thenR = R Β± d - Indexed Mode
Effective address = Base address (instruction) + Index register.E.A = Address + IndexReg - PC-Relative Mode
Effective address = PC (next instruction address) + Offset (instruction).E.A = PC + Offset - Base Register Mode
Effective address = Base register + Offset (instruction).E.A = BaseReg + Offset
Displacement Addressing Modes
Section titled βDisplacement Addressing ModesβEA = Register + Displacement/Offset
1. Indexed Mode β
Effective address = Base address (from instruction) + Index (from index register)
E.A = Address + (IndexReg)
-
Fixed / Not changeable: Address field (Base Address)
-
Changeable: IndexReg value
- Use: Arrays / tables / strings
- Why: Base points to start of array, index selects element number
Instruction ββββββββββββ¬βββββββββββ¬ββββββββββ β Opcode β Mode β Address β = Base Address (constant in instruction) ββββββββββββ΄βββββββββββ΄ββββ¬ββββββ Base Address β ββββββββ΄ββββββββββββ β ADD ( + ) β ββββββββ¬ββββββββββββ β ββββββββββββ β β IndexReg βββββ (changes during execution) ββββββ¬ββββββ Index β E.A β βββββββββββββ β Operand β = M[E.A] βββββββββββββExample (Array):
Address = Base of A[0]IndexReg = i * size- Access
A[i]
2. PC-Relative Mode (Position Independent Mode) β
Effective address = PC (next instruction address) + Offset (from instruction)
E.A = PC + Offset
- Fixed / Not changeable:
Offsetfield (in instruction) - Changeable:
PCvalue (keeps changing automatically) -
Use: Branch / jump inside code segment (loops, if-else)
- Why: Code can be loaded anywhere β jump still works (Position Independent Code)
Instruction ββββββββββββ¬βββββββββββ¬ββββββββββ β Opcode β Mode β Address β = Offset (constant in instruction) ββββββββββββ΄βββββββββββ΄ββββ¬ββββββ Offset β ββββββββ΄ββββββββββββ β ADD ( + ) β ββββββββ¬ββββββββββββ β βββββββββββ β ββββ΄ββββ β PC β (changes every instruction) ββββ¬ββββ Addr of NEXT instruction β E.A β ββββββββββββββββ β Target Instr β = M[E.A] ββββββββββββββββNotes:
- PC contains address of next instruction, not current.
- Forward jump:
Offset +ve - Backward jump:
Offset -ve
Example:
BEQ labelOffset = label - (PC of next instr)
Base Register Mode (Inter-Segment Branch)
Effective address = Base Register + Offset (from instruction)
E.A = (BaseReg) + Offset
- Fixed / Not changeable:
Offsetfield - Changeable:
BaseRegvalue -
Use: Segment based addressing, relocation, dynamic memory blocks, inter-segment jump
- Why: Base register selects the memory region/segment, offset selects inside it
Instruction ββββββββββββ¬βββββββββββ¬ββββββββββ β Opcode β Mode β Address β = Offset (constant in instruction) ββββββββββββ΄βββββββββββ΄ββββ¬ββββββ Offset β ββββββββ΄ββββββββββββ β ADD ( + ) β ββββββββ¬ββββββββββββ β ββββββββββββ β β BaseReg βββββ (changeable by program) ββββββ¬ββββββ Base β E.A β ββββββββββββββββ β Target/Opnd β = M[E.A] ββββββββββββββββExample:
- BaseReg = start address of segment (code/data/stack)
- Offset = location inside that segment
Key Differences (Most Important)
Indexed Mode: E.A = Address + IndexRegPC-Relative Mode: E.A = PC + OffsetBase Reg Mode: E.A = BaseReg + Offset| Point | Indexed Mode | PC-Relative Mode | Base Register Mode |
|---|---|---|---|
| EA formula | EA = Address + IndexReg | EA = PC + Offset | EA = BaseReg + Offset |
| Constant part comes from | Instruction Address field (Base Address) | Instruction Address field (Offset) | Instruction Address field (Offset) |
| Variable part comes from | Index Register | PC register | Base Register |
| Which register is used | Special/general Index Reg | PC only (fixed register) | Special/general Base Reg |
| What changes frequently | IndexReg changes | PC changes automatically every instruction | BaseReg changes when segment/region changes |
| What stays same mostly | Base address (array start) | Offset for that branch instruction | Offset inside segment |
| Main purpose | Array/Table access | Branch/Jump (control flow) | Relocation/Segmentation |
| Typical operand | Data (A[i]) | Instruction address (label target) | Data/Instruction inside a segment |
| Best use-case | Strings, arrays, lookup tables | Loops, if-else, function local jumps | Memory segments, modules, dynamic blocks |
| Why needed | Efficient element selection | Position independent code | Segment relocation with single register update |
| Example meaning | A[i] | goto label | access segment_base + k |
Similarity
E.A = (Some Register) + (Some Constant from instruction)
- Instruction (Fixed)
Address(in Indexed Register Mode)Offset(in PC-Relative and Base Register Mode)
- Register (Changeable)
IndexReg(in Indexed Register Mode)PC(in PC-Relative Mode)BaseReg(in Base Register Mode)
What changes?
- Indexed: Index changes β moving across array elements
- PC-relative: PC changes β branch depends on current location
- Base reg: BaseReg changes β switch segment / memory region
Best use:
- Indexed: arrays/tables
- PC-relative: short/near jumps, loops, position-independent code
- Base register: segment relocation, far addressing, inter-segment jumps
Similarity & Difference (Indexed vs PC-Relative vs Base Register Modes)
Section titled βSimilarity & Difference (Indexed vs PC-Relative vs Base Register Modes)βWhat is SAME (core similarity)
Section titled βWhat is SAME (core similarity)β- Instruction provides a constant displacement
- Indexed: constant = Base Address
- PC-relative/Base: constant = Offset
- One register provides a variable part
- CPU does addition to get E.A
What is DIFFERENT (real difference)
Section titled βWhat is DIFFERENT (real difference)β1) Indexed Mode
E.A = Address + IndexReg
-
Register is IndexReg== (a normal register ==chosen by programmer)
- It changes because you change it (loop variable i)
- Purpose: Data access pattern
- arrays, tables, strings
Meaning:
βBase is fixed, index moves element-to-elementβ
2) PC-Relative Mode
E.A = PC + Offset
- Register is PC (not selectable)
-
It changes automatically every instruction
- Purpose: Control flow
- branch/jump target
Meaning:
βTarget is near current instructionβ
Main benefit: Position Independent Code (PIC) (load program anywhere, jumps still work)
3) Base Register Mode
E.A = BaseReg + Offset
- Register is BaseReg (chosen/maintained by system/program)
-
It changes when segment/region changes
- Purpose: Relocation / segmentation
- move whole block by changing base
Meaning: βOffset stays same, but base shifts entire regionβ
Why 3 types if formula same?
Because they solve 3 different problems:
- Indexed β where is
A[i]? (data traversal) - PC-relative β where is next code label? (branch target)
- BaseReg β where is my segment/block currently located? (relocation)
Best 3-line exam difference
- Indexed: for arrays/tables ($IndexReg$ changes)
- PC-relative: for branches/jumps ($PC$ changes automatically)
- Base register: for relocation/segments ($BaseReg$ changes when region shifts)