8086 Addressing Modes:
We have seen how the 8086 fetches code bytes from memory by generating 20-bit physical address with the help of IP and CS. We have also seen how the 8086 accesses the stack using SS and SP. In this section we will see the different ways that an 8086 can access the data. The different ways that a processor can access data are referred to as 8086 Addressing Modes.
The 8086 has 12 basic addressing modes. The various 8086 addressing modes can be classified into five groups
- Addressing modes for accessing immediate and register data (register and immediate modes).
- Addressing modes for accessing data in memory (memory modes)
- Addressing modes for accessing I/O ports (I/O modes)
- Relative addressing mode
- Implied addressing mode
Addressing Modes for Accessing Immediate and Register Data (Register and Immediate Modes):
a) Register Addressing Mode
This mode specifies the source operand, destination operand, or both to be contained in an 8086 register.
b) Immediate Addressing Mode
In an immediate mode, 8 or 16-bit data can be specified as a part of instruction.
8086 Addressing Modes for Accessing Data In Memory (Memory Modes):
As mentioned before, the Execution Unit (EU) has direct access to all registers and data for register and immediate operands. However, the EU cannot directly access the memory operands. It must use the BIU segment registers to access memory. operands. For example, when the EU needs to access a memory location, it sends an offset value to the BIU. This offset is also called the Effective Address (EA). Note that EA is displacement of the desired location from the segment base. As mentioned before, the BIU generates a 20-bit physical address after shifting the contents of the desired segment register four bits to the left and then adding the 16-bit EA to it.
There are six ways to specify effective address (EA) in the instruction.
- Direct addressing mode
- Register indirect addressing mode
- Based addressing mode
- Indexed addressing mode
- Based indexed addressing mode
- String addressing mode.
a) Direct Addressing Mode :
In this mode, the 16-bit effective address (EA) is taken directly from the displacement field of the instruction. The displacement (unsigned 16-bit or sign-extended 8-bit number) is stored in the location following the instruction opcode.
b) Register Indirect Addressing Mode :
In this mode, the EA is specified in either a pointer register or an index register. The pointer register can be either base register BX or base pointer register BP and index register can be either Source Index (SI) register or Destination Index (DI) register. The 20-bit physical address is computed using DS and EA.
c) Based Addressing Mode :
In this mode, EA is obtained by adding a displacement (signed 8-bit or unsigned 16-bit) value to the contents of BX or BP. The segment registers used are DS and SS. When memory is accessed, the 20-bit physical address is computed from BX and DS. On the other hand, when the stack is accessed, the 20-bit physical address is computed from BP and SS.
d) Indexed Addressing Mode :
In this mode, the effective address is calculated by adding the unsigned 16-bit or sign-extended 8-bit displacement and the contents of SI or DI.
e) Based Indexed Addressing Mode :
In this mode, the EA is computed by adding a base register (BX or BP), an index register (SI or DI), and a displacement (unsigned 16-bit or sign extended 8-bit).
f) String Addressing Mode :
This mode uses index registers. The string instructions automatically assume SI to point to the first byte or word of the source operand and DI to point to the first byte or word of the destination operand. The contents of SI and DI are automatically incremented (by clearing DF to 0 by CLD instruction) or decremented (by setting DF to 1 by STD instruction ) to point to the next byte or word. The segment register for the source is DS. The segment register for the destination must be ES.
8086 Addressing Modes for Accessing I/O Ports (I/O Modes):
Standard I/O devices uses port addressing modes. For memory-mapped I/O, memory addressing modes are used. There are two types of port addressing modes : direct and indirect.
In direct port mode, the port number is an 8-bit immediate operand. This allows fixed access to ports numbered 0 to 255.
Relative Addressing Mode:
In this mode the operand is a signed 8-bit displacement relative to PC.
Implied Addressing Mode:
Instructions using this mode have no operands.