Addressing Modes
Addressing Modes
The different ways of specifying the location of an operand in an instruction are called as addressing modes.
1. Implied Addressing Mode-
Examples-
Example-
ADD
This instruction simply pops out two symbols contained at the top of the stack.
The addition of those two operands is performed.
The result so obtained after addition is pushed again at the top of the stack.
Examples-
The address field of the instruction contains the effective address of the operand.
Only one reference to memory is required to fetch the operand.
It is also called as absolute addressing mode.
Example-
ADD X will increment the value stored in the accumulator by the value stored at memory location X.
AC ← AC + [X]
The address field of the instruction specifies the address of memory location that contains the
effective address of the operand.
Two references to memory are required to fetch the operand.
Example-
ADD X will increment the value stored in the accumulator by the value stored at memory location
specified by X.
AC ← AC + [[X]]
6. Register Direct Addressing Mode-
Example-
ADD R will increment the value stored in the accumulator by the content of register R.
AC ← AC + [R]
NOTE-
The address field of the instruction refers to a CPU register that contains the effective address
of the operand.
Only one reference to memory is required to fetch the operand.
Example-
ADD R will increment the value stored in the accumulator by the content of memory location specified
in register R.
AC ← AC + [[R]]
NOTE-
Effective address of the operand is obtained by adding the content of program counter with the
address part of the instruction.
Effective Address
NOTE-
Program counter (PC) always contains the address of the next instruction to be executed.
After fetching the address of the instruction, the value of program counter immediately
increases.
The value increases irrespective of whether the fetched instruction has completely executed or
not.
9. Indexed Addressing Mode-
Effective address of the operand is obtained by adding the content of index register with the
address part of the instruction.
Effective Address
10. Base Register Addressing Mode-
Effective address of the operand is obtained by adding the content of base register with the
address part of the instruction.
Effective Address
11. Auto-Increment Addressing Mode-
This addressing mode is a special case of Register Indirect Addressing Mode where-
After accessing the operand, the content of the register is automatically incremented by step
size ‘d’.
Step size ‘d’ depends on the size of operand accessed.
Only one reference to memory is required to fetch the operand.
Example-
Here,
After fetching the operand 6B, the instruction register RAUTO will be automatically incremented by
2.
Then, updated value of RAUTO will be 3300 + 2 = 3302.
At memory address 3302, the next operand will be found.
NOTE-
This addressing mode is again a special case of Register Indirect Addressing Mode where-
Example-
Here,
NOTE-
Syntax Of Addressing Modes-
Syntax-
# Expression
Interpretation-
Operand = Expression
Examples-
Syntax-
Constant
Interpretation-
Operand = [Constant]
Examples-
Load R1, 1000 is interpreted as R1 ← [1000]
ADD R2, 3 is interpreted as R2 ← [R2] + [3]
Interpretation-
Operand = Content of the register Rn
Operand = [Rn]
Examples-
Load R1, R2 is interpreted as R1 ← [R2]
ADD R1, R2 is interpreted as R1 ← [R1] + [R2]
4. Indirect Addressing Mode-
Syntax-
@Expression or @(Expression) or (Expression)
Interpretation-
Effective address of the operand = Content of the memory location ‘expression’
Operand = [[ Expression]]
Examples-
Load R1, @1000 is interpreted as R1 ← [[1000]]
ADD R1, @(1000) is interpreted as R1 ← [R1] + [[1000]]
ADD R1, (1000) is interpreted as R1 ← [R1] + [[1000]]
Interpretation-
Effective address of the operand = Content of the register Rn
Operand = [[ Rn ]]
Examples-
Load R1, @R2 is interpreted as R1 ← [[R1]]
ADD R1, @(R2) is interpreted as R1 ← [R1] + [[R2]]
ADD R1, (R2) is interpreted as R1 ← [R1] + [[R2]]
Interpretation-
Effective address of the operand = disp + Content of the register Rn
Examples-
Load R1, 100(R2) is interpreted as R1 ← [100 + [R1]]
ADD R1, 100(R2) is interpreted as R1 ← [R1] + [100 + [R2]]
7. Auto-Increment Addressing Mode-
Syntax-
(Rn)+
Interpretation-
Effective address of the operand = Content of the register Rn
Operand = [[ Rn ]]
Examples-
Interpretation-
Before fetching the operand, decrement [Rn] by step size ‘d’
Operand = [[ Rn ]]
Examples-
Load R1, -(R2) is interpreted as R2 ← [R2] – d followed by R1 ← [[R2]]
ADD R1, -(R2) is interpreted as R2 ← [R2] – d followed by R1 ← [R1] + [[R2]]
PRACTICE PROBLEMS BASED ON ADDRESSING MODES-
Problem-01:
The most appropriate matching for the following pairs is-
Column-1:
X: Indirect addressing
Y: Immediate addressing
Column-2:
1. Loops
2. Pointers
3. Constants
Problem-02:
In the absolute addressing mode,
Problem-03:
Which of the following addressing modes are suitable for program relocation at run time?
1. Absolute addressing
2. Base addressing
3. Relative addressing
4. Indirect addressing
1. 1 and 4
2. 1 and 2
3. 2 and 3
4. 1, 2 and 4
Solution-
Option (C) is correct.
Problem-04:
What is the most appropriate match for the items in the first column with the items in the second
column-
Column-1:
X: Indirect addressing
Y: Indexed addressing
Column-2:
1. Array implementation
Problem-05:
Which of the following addressing modes permits relocation without any change whatsoever in the
code?
1. Indirect addressing
2. Indexed addressing
3. Base register addressing
4. PC relative addressing
Solution-
Problem-06:
ADD A[R0], @B
The first operand (destination) “A[R0]” uses indexed addressing mode with R0 as the index register. The
second operand operand (source) “@B” uses indirect addressing mode. A and B are memory
addresses residing at the second and the third words, respectively. The first word of the instruction
specifies the opcode, the index register designation and the source and destination addressing modes.
During execution of ADD instruction, the two operands are added and stored in the destination (first
operand).
The number of memory cycles needed during the execution cycle of the instruction is-
1. 3
2. 4
3. 5
4. 6
Solution-
The operands will be added and result is stored back in the memory.
Thus, one memory cycle will be needed to store the result.
= 1 + 2 + 1
=4
Problem-07:
Consider a hypothetical processor with an instruction of type LW R1, 20(R2), which during execution
reads a 32-bit word from memory and stores it in a 32-bit register R1. The effective address of the
memory location is obtained by the addition of a constant 20 and the contents of register R2. Which of
the following best reflects the addressing mode implemented by this instruction for operand in
memory?
1. Immediate Addressing
2. Register Addressing
3. Register Indirect Scaled Addressing
4. Base Indexed Addressing
Solution-
Problem-08:
The memory locations 1000, 1001 and 1020 have data values 18, 1 and 16 respectively before the
following program is executed.
Rd,
LOAD Load from memory
1000(Rs)
Which of the statements below is TRUE after the program is executed?
After the program execution is completed, memory location 1001 has value 20.
Option (D) is correct.
To watch video solution, click here.
Problem-09:
Consider the following memory values and a one-address machine with an accumulator, what values
do the following instructions load into accumulator?
Word 20 contains 40
Word 30 contains 50
Word 40 contains 60
Word 50 contains 70
Instructions are-
1. Load immediate 20
2. Load direct 20
3. Load indirect 20
4. Load immediate 30
5. Load direct 30
6. Load indirect 30
Solution-