2. ADDRESSING MODES
• Each instruction has 2 fields
• Operation code (Opcode) field
• Operand field
• The operand field holds the operands or the reference to operands
• Addressing modes specify the ways in which effective address of the operand is
represented in the instruction
• Effective address(EA) is the exact memory location where the value of the operand
is stored
• In an instruction set different addressing modes are used for different types of
instructions
Opcode operand
2
2/27/2021
DR. PRASENJIT DEY
Instruction
3. TYPES OF ADDRESSING MODE
• Inherent / Implied
• Immediate
• Direct
• Indirect
• Register
• Register Indirect
• Displacement
• Relative
• Indexed
• Auto-decrement or auto-increment
• Stack
3
2/27/2021
DR. PRASENJIT DEY
4. INHERENT / IMPLIED ADDRESSING
• In this type of addressing, operand is part of the opcode field
• e.g., CLC
• Clear carry flag to zero
4
2/27/2021
DR. PRASENJIT DEY
• Speed
• No need to fetch operand
• Fast
• Address space
• Fixed range, depends on instruction set
5. IMMEDIATE ADDRESSING
• In this type of addressing, operand is part of instruction
• Operand field = operand
• e.g., SUB #17
• Here, the instruction will subtract 17 from the content of the accumulator and
load the result in the accumulator
• Ac Ac - 17
5
2/27/2021
DR. PRASENJIT DEY
• Speed
• No reference for fetching the operand
• Fast
• Address space
• Instruction format provides a limited size for operand so limited range
Opcode 17
Opcode field Operand field
6. DIRECT / ABSOLUTE ADDRESSING
• Here, operand field holds memory address of the operand
• Operand field = address of the operand = EA
• e.g., LDA A, [12]
• Load the data content at memory location 12 into the A register
• A M[12]; EA = 12
Opcode [12]
6
2/27/2021
DR. PRASENJIT DEY
• Speed
• Single memory reference to access data
• No extra computation is required to get the effective address of the data
• Address space
• Range depends on the size of memory address space
8. INDIRECT ADDRESSING
• Memory address pointed to by operand field contains the address of the operand
• Operand field = address of the [EA]
• e.g., ADD A, @12
• Add content of memory location pointed to by memory location 12 into A register
• Temp M[12]; A A + M[Temp]; EA = 12
• can be multilevel, cascaded
Opcode @12
8
2/27/2021
DR. PRASENJIT DEY
• Speed
• Comparatively slow as multiple (generally 2) memory access are required to get
the data
• Address space
• 2n where n = word length
10. REGISTER ADDRESSING
• Here, operand field holds the name of the register which contains the operand
• Operand field = R (name of the register)
• EA = R
• e.g., ADD A, B
• Add the content of B register with the content of A register and load the result into A
register
• A A + B
Opcode A B
10
2/27/2021
DR. PRASENJIT DEY
• Speed
• Limited registers smaller operand field shorter instructions faster fetch
• No memory access, very fast execution
• Address space
• Registers have limited address space so limited range
12. REGISTER INDIRECT ADDRESSING
• Operand field holds the name of the register which contains memory location of the
operand
• Operand field = R (name of the register/register pair)
• e.g., ADD A, (B)
• Add the content of memory location pointed by B register with A register and store
the result into A register
• A A + M[B];
Opcode A ( B)
12
2/27/2021
DR. PRASENJIT DEY
• Speed
• One register access and one memory access is required to get the data
• Address space
• Large address space: 2n where n = word length
14. DISPLACEMENT ADDRESSING
• Operand field contains two values:
1. Base register (B)
2. Offset value (R)
• Addition of offset value with base register value provides the effective
address of the operand
• EA = (B) + R
• e.g., ADD A, 12(B)
• Useful in accessing local variables
14
2/27/2021
DR. PRASENJIT DEY
16. RELATIVE ADDRESSING
• A version of displacement addressing
• B = Base register = Program counter (PC)
• R = Address part of the instruction
• EA = (PC) + R
• Addition of offset field value with PC register value provides the
effective address of the operand
• e.g., ADD A, 4(PC)
1. Add 4 with PC value and form EA=(PC+4)
2. A A + PC[4]
• Used in control transfer instructions
16
2/27/2021
DR. PRASENJIT DEY
18. INDEXED ADDRESSING
• A version of displacement addressing
• B = Base register = Index register
• R = Address part of the instruction
• EA = (B) + R
• e.g., ADD A, 04(B)
1. Add 4 with B register value and form EA = (B+4)
2. A A + B[4]
• Useful in array addressing
• B = base address of the array
• R = index amount
18
2/27/2021
DR. PRASENJIT DEY
20. AUTO-INCREMENT OR AUTO-DECREMENT
ADDRESSING
• In case of auto-increment addressing
• B = base address of the array
• d = size of each element in the array
• e.g., ADD A, (B)+
1. A A + M[B]
2. B B + d
20
2/27/2021
DR. PRASENJIT DEY
• Useful when iterating through array in a loop
• Used to implement a stack as push and pop
• In case of auto-decrement addressing
• B = base address of the array
• d = size of each element in the array
• e.g., ADD A, -(B)
1. B B - d;
2. A A + M[B]
21. STACK ADDRESSING
• Operand is (implicitly) on top of stack
• e.g. ADD
• Pop top two items from stack and add and push result on top
21
2/27/2021
DR. PRASENJIT DEY
40
08
45
14
12
48
45
14
12
Before the operation After the operation
22. ADDRESSING MODES FOR DIFFERENT
INSTRUCTIONS
• Load/store instructions
• displacement and indexed addressing
22
2/27/2021
DR. PRASENJIT DEY
• Branch instructions
• Direct / Absolute addressing
• Relative addressing
• Register indirect addressing
• Arithmetic and logical instructions
• Immediate addressing
• Register addressing
• Register indirect addressing