Addressing modes specifies the way, the effective address of an operand is represented in the instruction. Some addressing mode efficiently allows referring to a large range of area like a linear array of addresses and list of addresses. Addressing mode describes a flexible and efficient way to define complex effective address.
Generally, the programs are written in a high-level language, as it is a convenient way to define the variables and operations that the programmer needs to perform on the variables. Later, this program is compiled to generate the machine code. The machine code has low-level instructions.
The low-level instruction has opcode and operands. Addressing mode has nothing to do with the opcode part. It focuses on presenting the operand’s address in the instructions.
We have the list below showing the various kind of addressing modes:
Types of Addressing Modes
- Register Addressing Mode
- Direct Addressing Mode
- Immediate Addressing Mode
- Register Indirect Addressing Mode
- Index Addressing Mode
- Auto Increment Mode
- Auto Decrement Mode
- Relative Addressing Mode
Before discussing the addressing modes, we must know about the term “effective address”.
Effective Address (EA):
Effective address is the address of the exact memory location where the value of the operand is present.
1. Register Addressing Mode
Every instruction includes operands; the operands can be a memory location, a processor register or an I/O device. The instruction which uses processor registers to represent operands is the instruction in register addressing mode.
Here, the effective address is a register where the value of the operand is present.
Below we have two instructions as our examples for register addressing mode.
Add R4, R3
Load R3, R2
In the examples above, the Add instruction uses registers to represent both of its operands. Similarly, the Load instruction also uses registers to represent both of its operands. So, the instruction above uses register addressing mode to describe the address of the operand. Below, we have a figure showing the Add instruction in the example above.
Advantage: In the register addesing mode there are no memory references as the value to be operated is present in the register.
Disadvantage: Registers have limited address space. So, it has a limit on the size of value that can be stored.
2. Direct Addressing Mode
The direct addressing mode is also known as Absolute Addressing mode. Here, the instruction contains the address of the location in memory where the value of the operand is stored.
Here, the effective address is the address of memory location.
EA = A
For example, observe the examples below:
Add R2, A
Store R2, B
The Add instruction includes the memory location A which has the value to be added to the content of register R2. Similarly, the Store instruction has the address of memory location B where the content of register R2 will be stored. Below we have a figure showing the direct addressing of the operand A in the Add instruction of the example above.
3. Immediate Addressing Mode
In immediate addressing mode, the value of the operand is explicitly mentioned in the instruction. Here, effective address is not required as the operand is explicitly defined in instruction.
Let us see the example of immediate addressing mode:
Add R2, #100
Store R2, 100H
The Add instruction, adds 100 to R2’s content . The # sign in front of the value indicates the immediate value to be operated. If a value does not have # sign in front of it then it is the address of a memory location.
The next instruction Store considers the immediate value 100H as address as it does not have # sign in front of it. The Store instruction stores the content of R2 at memory location 100H. In the figure below we have shown the Store instruction of the above examples.
Advantage: In the immediate addressing mode the memory reference is not required as the value is explicitly present in the instruction
4. Register Indirect Addressing mode
A processor register is used to hold the address of a memory location where the operand is placed. This addressing mode allows executing the same set of instructions for the different memory location. This can be done by incrementing the content of register thereby pointing the new location each time.
In higher-level language, it is referred to as pointers. The indirect mode is denoted by placing the register inside the parenthesis.
Here the effective address is the content of memory location present in the register.
Now, for example:
Load R3, (R2) // Load R2, A
The Load instruction above will load the value present at the memory location contained by register R2 in the register R3. The figure below shows how the register R3 gets loaded with the value stored in the memory location held by register R2.
Advantage: In the register indirect addressing mode the same set of instructions can be used multiple times.
5. Index Addressing Mode
Index addressing mode is helpful when the instructions in the program are accessing the array or the large range of memory addresses. In this mode, the effective address is generated by adding a constant to the register’s content. The content of the register does not change.
The symbolic representation of index addressing mode is denoted as:
And the effective address is denoted by
EA = X + (R)
For example, consider the instruction below:
Load R2, A
Load R3, (R2)
Load R4, 4(R2)
Load R5, 8(R2)
Load R6, 12(R2)
The above instructions will load the register R3, R4, R5, R6 with the contents, present at the successive memory addresses from memory location A correspondingly.
Advantage: The index addressing mode provides flexibility to specify memory locations.
6. Auto Increment Addressing Mode
In auto-increment addressing mode once the content of the register is accessed by the instruction the register’s content is incremented to refer the next operand.
Symbolically it is represented as below:
Here, the effective address is content of the register as it is enclosed by parenthesis. The content of register which is referring to a memory location is incremented so that it could point the next memory location where the next operand is stored.
7. Auto Decrement Addressing Mode
It is just opposite of auto-increment mode. In auto decrement mode the content of the register is decremented initially and then the decremented content of the register is used as effective address.
Symbolically it is presented as:
8. Relative Addressing Mode
In the content above we have discussed the index addressing mode. There we were adding a constant to the register content to refer the next operand address. In some computer instead of a register, the program counter is used.
The symbolic representation of relative address mode is
The effective address for it would be:
EA = X + (PC)
As here the operand addresses are found relative to the program counter. That’s why it is referred to as relative address mode.
Advantage: Relative addressing mode doesn’t require memory references.
Disadvantage: Relative addressing mode doesn’t have any disadvantage as such.
This is all about addressing modes in computer architecture. It provides us with a flexible method to specify the address of the operands used in instruction.