What Is Addressing Mode
What Is Addressing Mode
Addressing modes are different ways by which CPU can access data or operands. They
determine how to access a specific memory address. To load any data from and to
memory/registers, MOV instruction is used. The syntax of MOV instruction is:
It copies the data of 2nd operand (source) into the 1st operand (destination). To access
memory, segment registers are used along with general-purpose registers.
There are seven addressing modes in 8086 processor. Now, we will discuss all of them in
detail with example assembly instructions.
For example:
MOV AX, BL
MOV AL, BL
The above two instructions copy the data of BL register to AX and AL.
The ORG 100h is a directive which tells the compiler how to handle the source code.
ORG 100h
MOV AX,CX
ret
Output:
In this example, you can see a red box in the output. This red box indicates the content of AX
and CX registers. The content of both AX and CX registers are the same. Because the above
example moves the content of CX into AX register.
For example:
The instruction MOV AX, 30H copies hexadecimal value 30H to register AX.
The instructions MOV BX, 255 copies decimal value 255 to register BX.
You cannot use the immediate addressing mode to load immediate value into segment registers.
To move any value into segment registers, first load that value into a general-purpose register
then add this value into segment register.
Example Assembly Code
Output
If 0320h is added directly into the DS register using MOV instruction, the compiler will generate
an error.
3. Direct Addressing Mode
It loads or stores the data from memory to register and vice versa. The instruction consists of a
register and an offset address. To compute physical address, shift left the DS register and add the
offset address into it.
Example Code
ORG 100h
MOV AX, 2162H ;copies hexadecimal value 2162h to AX
MOV DS, AX ;copies value of AX into DS
MOV CX, 24 ;copies decimal value 24 into CX
MOV [481], CX ;stores the data of CX to memory address 2162:01E1
MOV BX, [481] ;load data from memory address 2162:01E1 into BX
RET ;stops the program
Output
In this example, the red box indicates the hexadecimal value 18 and decimal value 24 is stored at
memory address 21801h.
This instruction will calculate the physical address by shifting DS to the left by one position and
adding it to the offset address residing in SI. The brackets around SI indicates that the SI contain
the offset address of memory location whose data needs to be accessed. If brackets are absent,
then the instruction will copy the contents of SI register to AL. Therefore, brackets are necessary.
Example Code
ORG 100h
MOV AX, 0708h ;set AX to hexadecimal value of 0708h.
MOV DS, AX ;copy value of AX to DS
MOV CX, 0154h ;set CX to hexadecimal value of 0154h.
MOV SI, 42Ah ;set SI to 42Ah.
MOV [SI], CX ;copy contents of CX to memory at 0708:042Ah
RET ;returns to operating system
Output
In the above example, the physical address is 07080 + 042A = 74AA. According to the little-
endian convention, the 074AA will store the lowest bytes of data i.e., 54 and the 074AB will
store the most significant bits of data i.e. 01.
5. Based Relative Addressing Mode
This addressing mode uses a base register either BX or BP and a displacement value to calculate
physical address.
The effective address is the sum of offset register and displacement value. The default segments
for BX and BP are DS and SS. For example:
MOV [BX+5], DX
In this example, the effective address is BX + 5 and the physical address is DS (shifted left) +
BX+5. The instruction on execution will copy the value of DX to memory location of physical
address= DS (shifted left) +BX+5.
Example 1 Code
ORG 100h
MOV AX, 0708h ;set AX to hexadecimal value of 0708h.
MOV DS, AX ;copy value of AX to DS
MOV CX, 0154h ;set CX to hexadecimal value of 0154h.
MOV BX, 42Ah ;set BX to 42Ah.
MOV [BX+5],DX ;copy contents of DX to memory at 0708:042Fh
RET ;returns to operating system
Output
MOV [BX+10], DX
Now, suppose the base register is BP. Then, in this case, the default segment would be SS. In the
above example, replace BX by BP. Now the physical address is equal to SS (shifted left) +BX+5
which is equal to 742F.
Example 2 Code
ORG 100h
MOV AX, 0708h ;set AX to hexadecimal value of 0708h.
MOV DS, AX ;copy value of AX to DS
MOV DX, 0154h ;set DX to hexadecimal value of 0154h.
MOV BP, 42Ah ;set BP to 42Ah.
MOV [BP+5],DX ;copy contents of DX to memory at 0708:042Fh
RET ;returns to operating system
Output
For example:
MOV [DI]+12, AL
This instruction on execution will copy the content of AL at memory address 7197 (7040 + 145
+ 12)
MOV BX, [SI]+10
This instruction will load the contents from memory address 7302 (7040 +2B2 +10) to register
BX.
In this case, the physical address will be DS (Shifted left) + SI + BX + 20. Now, if we replace
BX with BP then the physical address is equal to SS (Shifted left) + SI + BX + 20.
Example Code
ORG 100h
MOV AX, 0708h ;set AX to hexadecimal value of 0708h.
MOV SS, AX ;copy data of AX to DS
MOV DX, 0154h ;store hexadecimal value of 0154h in DX.
MOV BP, 42Ah ;store hexadecimal value of 42Ah in BP.
MOV DI, 213h ;store hexadecimal value of 213h inDI
MOV [BP+DI+20],DX ;copy contents of DX to memory address 0708:0651
RET ;stops the program
Output
In conclusion, addressing modes are ways to access the operands. The programmer can use any
of these seven addressing modes depending upon the program.