Sub topic 6
Addressing Modes and Why They Exist
Prerequisites: binary and hexadecimal numbers, registers, memory, and basic instruction formats. An addressing mode is the rule an instruction uses to locate its operand. The same operation, such as LOAD, can use different modes depending on whether the value is inside the instruction, a register, or memory.
Effective addresses
The effective address (EA) is the memory address calculated for an operand. Some modes do not produce an effective address because the operand is already in the instruction or a register.
| Mode | Address field means | Operand location |
|---|---|---|
| Immediate | The value itself | Inside the instruction |
| Register | A register name | The named register |
| Direct | A memory address | Memory at that address |
| Indirect | A memory address containing an address | Memory at the retrieved address |
| Register indirect | A register containing an address | Memory at the register value |
| Indexed | An address plus an index register | Memory at the calculated address |
| Relative | The program counter plus an offset | Memory at the calculated address |
For example, suppose R1 = 100, XR = 4, and memory location 100 contains 500. If memory location 500 contains 7:
- Immediate operand
7gives the value 7. - Register operand
R1gives the value 100. - Direct operand
100accesses memory[100], giving 500. - Indirect operand
100first reads memory[100] as 500, then accesses memory[500], giving 7. - Register-indirect operand
R1accesses memory[100], giving 500. - Indexed operand
96(XR)calculates96 + 4 = 100, then reads memory[100].
def fetch_operand(mode, x, registers, memory):
if mode == "immediate":
return None, x
if mode == "register":
return None, registers[x]
if mode == "direct":
effective_address = x
elif mode == "indirect":
effective_address = memory[x]
elif mode == "register_indirect":
effective_address = registers[x]
elif mode == "indexed":
effective_address = x + registers["XR"]
else:
raise ValueError(f"unknown mode: {mode}")
return effective_address, memory[effective_address]
memory = {96: 12, 100: 500, 500: 7}
registers = {"R1": 100, "XR": 4}
print(fetch_operand("immediate", 7, registers, memory))
print(fetch_operand("indirect", 100, registers, memory))
print(fetch_operand("indexed", 96, registers, memory))Why processors use several modes
Addressing modes balance instruction size, execution speed, and programming convenience.
- Immediate mode is fast and avoids a memory read, but the value must fit in the instruction.
- Register mode is fast because registers are inside the processor.
- Direct mode is simple, but its address field limits the addressable memory range.
- Indirect mode supports pointers and dynamic data structures, but requires an additional memory access.
- Indexed and base-plus-offset modes support arrays, records, stacks, and relocation. A base register can hold the start of an object while the instruction supplies a small offset.
- Relative mode is useful for branches. It lets code move in memory while keeping nearby branch targets reachable.
A reliable solving method
For a GATE-style question:
- Identify the addressing mode.
- Write the formula for the effective address.
- Substitute register values and offsets.
- Read memory only as many times as the mode requires.
- Distinguish the final address from the operand stored there.
Exercise
Memory[200] = 700 and Memory[700] = 25. What operand does indirect addressing with address field 200 produce?
Show answer
It first computes EA = Memory[200] = 700, then reads Memory[700]. The operand is 25.