In the 8086 microprocessor, in order to perform an operation on data, an instruction is given to the microprocessor. The data on which the operation is performed are called operands. Addressing mode represents a method of assigning the address of the source of data or operand to the instruction given to the microprocessor. The addressing modes of the 8086 microprocessor is classified as,
- Register and Immediate Data Addressing Modes,
- Data Memory Addressing Modes,
- Program Memory Addressing Modes,
- Port Addressing Modes, and
- Stack Memory Addressing Modes.
Register and Immediate Data Addressing Modes :
Register Addressing Mode :
In register addressing mode, the data present in one register is manipulated or moved and stored in another register as shown in the below examples i.e., the register is the source of an operand in the instruction.
MOV AL, BL → Contents of BL are moved to AL
ADD CL, BL → Contents of BL are added with CL and the result is stored in CL
Immediate Addressing Mode :
In immediate addressing mode, the 8-bit or 16-bit data is given in the instruction itself (i.e., operand itself will be the part of the instruction) rather than register as seen in register addressing and is moved to a destination register or memory location.
MOV AL, 20H → Data 20H is moved to and stored in AL
MOV [SI], 230FH → Data 230FH is moved to the memory at [SI]
Data Memory Addressing Modes :
We know that all the register data and immediate operands can be accessed by the execution unit (EU) of the 8086 microprocessor. However the execution unit uses the bus interface unit (BIU) segment registers to access memory operands i.e., the execution unit sends an offset value also known as effective address (EA) to the BIU. The offset value is the displacement of the desired location from the segment base. The effective address or offset address in the instruction can be specified in the following ways,
- Direct addressing mode,
- Register indirect addressing mode,
- Base plus index addressing mode,
- Register relative addressing mode,
- Base relative plus index addressing mode, and
- String addressing mode.
Direct Addressing Mode :
In this addressing mode, the effective address (EA) or offset address (OA) located within the data segment (DS) is directly given in the instruction as displacement field. The displacement is given following the instruction opcode as a 16-bit unsigned or 8-bit sign-extended number.
Example : MOV AL, [1000H] {Offset address(OA) = 1000H}
Physical memory address = DS × 10H + OA
In the above instruction, the contents at offset address 1000H displaced from the data segment base are moved into the AL register.
Register Indirect Addressing Mode :
This type of addressing mode allows to specify the effective address at any memory location either in a pointer register (i.e., base pointer register BP or base register BX) or in an index register (source index register SI or destination index register DI) i.e., EA = (BX) or EA = (BP).
Example : MOV CL, [BX]
Physical memory address = DS × 10H + [BX]
The contents present in the address pointed by BX in DS are moved and stored in CL. Remember for SI, DI, and BX default segment register is DS, whereas for BP default segment register is SS.
Base Plus Index Addressing Mode :
The base plus index addressing mode is the extension of the register indirect addressing mode that indirectly addresses the memory data. This type of addressing mode is best suited for addressing the array of data. Here the memory location is indirectly addressed by combining both index register (DI or SI) and base register (BP or BX) i.e., offset address = (BX) + (SI).
Example : MOV AL, [BX + SI]
Physical memory address = DS × 10H + (BX) + (SI)
The contents present in the DS address which is given by the sum of addresses pointed by BX and SI is moved to AX.
Register Relative Addressing Mode :
This addressing mode is similar to the base plus index addressing mode. Here the index or base registers contents along with displacement constitute offset address of the instruction that addresses the data of a segment in memory i.e., offset address = (SI) ± 8 or 16-bit displacement. The displacement added can be of 8-bit or 16-bit number as shown in the below example.
Example : MOV CX, [BX + 0003H]
Physical memory address = DS × 10H + (SI) – 100H
The contents of the address in DS given by the combination of displacement and address pointed by BX are read and stored in CX.
Base Relative Plus Index Addressing Mode :
This addressing mode is similar to the base plus index addressing mode, but here to generate the physical address of the memory 8-bit or 16-bit displacement is added besides using base register and index register i.e., offset address = (BX) + (SI) + 8 or 16-bit displacement. The two-dimensional array data can be addressed with base relative plus index addressing.
Example : MOV CX, [BX + SI + 20H]
Physical memory address = DS × 10H + (BX) + (SI) + 20H
String Addressing Mode :
In order to access string operands, special instructions are used which can be done by string addressing mode. This addressing mode uses index registers (SI and DI). For source operand in the string, segment register DS and index register SI are used. For destination operand in the string, segment register ES and index register DI are used.
When the instruction is executed. If the direction flag DF = 0, the contents of SI and DI are incremented automatically, and if DF = 1, the contents of SI and DI are decremented automatically to point to the next byte of the string.
Port Addressing Modes :
To access the input and output ports of the 8086 microprocessor, port addressing modes are used. So that data from standard I/O mapped devices or ports is accessed. The ports are accessed with IN and OUT instructions. The port addressing modes are divided into two types, direct and indirect port addressing.
Direct I/O Port Addressing Mode :
In this addressing mode, an 8-bit port address is given in the instruction. Since the address is of 8-bit wide, ports numbered from 0 to 255 are accessed.
IN AX, 80H → The content of the port with 80H address is moved to the AX register.
Indirect I/O Port Addressing Mode :
In indirect port addressing, the register containing the port address is given in the instruction. In 8086 microprocessor, DX register provides 16-bit port address.
OUT DX, AX → The content of AX is moved to the port address present in the DX register.
Program Memory Addressing Modes :
The program memory addressing modes are used by the JMP (jump) and CALL instructions. There are three types of program memory addressing modes namely direct, relative and indirect.
Direct Program Memory Addressing :
In this type of addressing mode, the memory address (contains both segment and offset set address) represents the address to which the microprocessor has to transfer. This implies an inter-segment jump or far jump, as the microprocessor can jump to any memory location within the memory segment.
This instruction loads CS with 2000H and IP with 0000H. Thus microprocessor calculates the memory address and jumps to the memory location 2000H.
Relative Program Memory Addressing :
Relative JMP and CALL instructions are used to indicate relative addressing. In this, 8-bit or 16-bit signed displacement is added to the current instruction pointer (IP) to obtain the address of the next instruction (i.e., CS × 10H + IP). If displacement is negative, PC decrement by the magnitude of displacement. If displacement is positive, PC increments by displacement value.
Short jump and call instructions (uses one-byte displacement) and near jump and call instructions (uses two-byte displacement) are combinedly called intra-segment jumps as the program control is transferred within the current code segment. SHORT and NEAR PTR are used to indicate short and near jump respectively.
Indirect Program Memory Addressing :
In this type of addressing, the JMP and CALL instructions use a 16-bit register (AX, BX, CX, DX, SP, BP, DI, or SI), a relative register, or a relative register with displacement. It may be an inter-segment indirect jump or an intra-segment indirect jump.