Addressing modes are used in computer architecture to specify how operands are accessed in instructions. They determine the way memory or registers are referenced during the execution of a program. Every instruction has two fields .
- Op code
- Operand
The opcode specifies the operation to be performed and operand specifies the information required for this operation .The addressing mode indicates the way by which the operand are specified in the instruction .
We use different types of addressing modes for the following two purposes —-
- I. To make the program versatile.
- II. To reduce the number of bit in the instruction varying register and memory address.
The following addressing modes are generally used :-
- Register addressing mode .
- Immediate addressing mode .
- Direct addressing mode .
- Register indirect addressing mode .
- Base addressing mode .
- Index addressing mode .
o The different addressing modes are discussed bellow ::-
Register addressing mode :
In this addressing mode the operand to be access specified by an internal register of the processor .
Code : ADD R1, R2 ; Add the value in register R2 to register R1
Ex:– MOV A,B; MEANS B is the source register and A is the destination register and the content of B is copied or moved to register A .
MOV R1, C;
ADD C ;
Immediate addressing mode :
if the source operand is not a register or a memory address rather the data is specified in the operand part of the instruction, then the addressing mode is known as immediate addressing mode.
Code: MOV R1, #10 ; Move the immediate value 10 to register R1
Ex:-MV1 A, 15#; means 15# data is move into the register A immediately.
Direct addressing mode :
In this addressing mode the effective address is equal to the address of the memory location. The data resides in memory and its address is directly given in the operand part . The operand is accessed directly from memory using its address.
Code : MOV R1, [1000] ; Move the value from memory address 1000 to register R1
Ex:- LDA 2050H; means load the AC with content specified by the memory address 2050,similarly STA 2070H; means the content of AC is stored in the memory address 2070.
Register indirect addressing mode :
In this addressing mode the effective address of the data is specified in the instruction. A source or base register is used In the instruction which contain the address of the memory. The address of the operand is stored in a register. The instruction accesses the memory location pointed to by the register
Code: MOV R1, [R2] ; Move the value from the memory location pointed to by R2 to register R1
Ex:– 1) LDA X M;
2) STAX M;
1:>The control of the memory address specified in the H-L pair is transferred to the AC.
2:>The content of the AC is transferred to the address specified by the H-L pair .
Base addressing mode:
Here the effective address of the offset value is either the based register or the based pointer with the current value of source index register .and destination index register .The mode is commonly used in array access.
Code: MOV R1, [R2 + 4R3] ; Move the value from the memory location (R2 + 4R3) to register R1
Ex:– STAX [ M]+DI, A
This means the content of the AC is transferred to the address obtained by adding memory location and the value of destination index register.
Indexed addressing mode:
This address mode works similarly as the previous addressing mode but here the source address is to be calculated rather than the destination address.
Code :MOV R1, [R2 + 10] ; Move the value from the memory location (R2 + 10) to register R1
Ex:- LDA X A,[M]+ SI
Means the content of the memory address by adding the current value and the source index register value is transferred to the AC.
LDA X M; ‘M’ means H L Pair.
H | L |
20 | 70 |
H=8 bit, L=8 bit
Since every address contains 16 bit, this is why H-L pair is taken.
15H |
15H- Data
15H data is needed to be transferred in to
2070 address the accumulator :-> AC <-15H
15H |
2070 address containing the data 15H, Which
2070 is loaded into the accumulator .
STAX [M] + DI, A
[M]= H-L pair
05 |
H | L |
20 | 50 |
20H |
AC <-15H
2055 Means 2050H address
DI=05=2055H
The data 20H loaded in to the accumulator
Various processors and instruction sets might support different addressing modes or varieties of these modes to give adaptability and productivity in getting data and operands.
You can visit here for more details https://www.geeksforgeeks.org/addressing-modes/