Q2Microprocessor and Interfaces
Question
Explain the various addressing modes of the 8086 microprocessor.
Answer
The 8086 supports eight addressing mode categories - immediate, register, and six memory-operand variants (direct, register-indirect, based, indexed, based-indexed, and based-indexed with displacement) - which together generate the effective address using combinations of base, index and displacement fields.
An addressing mode defines how an instruction specifies the location of its operand. The 8086 offers a rich set of addressing modes so that arrays, records, and pointer-based structures used by high-level languages can be accessed efficiently in a single instruction. Every memory-operand mode ultimately computes an Effective Address (EA) which is then combined with a segment register to form the full 20-bit physical address.
Immediate and Register Addressing
- Immediate Addressing: The operand is a constant encoded directly in the instruction, e.g. MOV AX, 0500H loads the literal value 0500H into AX.
- Register Addressing: Both operands are CPU registers, e.g. MOV AX, BX copies BX into AX. This is the fastest mode since no memory access or address calculation is needed.
Memory Addressing Modes
- Direct Addressing: The instruction contains the 16-bit offset directly, e.g. MOV AX, [1500H] fetches the word at offset 1500H within the current data segment.
- Register Indirect Addressing: The offset is held in a base or index register (BX, SI, or DI), e.g. MOV AX, [BX] reads the word whose offset is the current value of BX.
- Based Addressing: The effective address is the sum of a base register (BX or BP) and a displacement coded in the instruction, e.g. MOV AX, [BX+04H]. Using BP implicitly selects the Stack Segment instead of the Data Segment.
- Indexed Addressing: The effective address is the sum of an index register (SI or DI) and a displacement, e.g. MOV AX, [SI+06H], commonly used to step through arrays.
- Based-Indexed Addressing: Combines a base register and an index register, e.g. MOV AX, [BX+SI], useful for accessing two-dimensional arrays or arrays of structures where BX holds a structure's base and SI an element offset.
- Based-Indexed with Displacement: Adds a base register, an index register, and a displacement, e.g. MOV AX, [BX+SI+02H], giving maximum flexibility for addressing a field within an element of an array of records.
Effective and Physical Address Calculation
Once EA is computed by the appropriate mode, the BIU forms the 20-bit physical address using the relevant segment register.
For example, if DS = 3000H and the based-indexed-with-displacement mode computes EA = BX+SI+02H = 0524H, the physical address referenced is (3000H x 10H) + 0524H = 30000H + 0524H = 30524H.
This layered addressing scheme - separating a 16-bit logical offset from a 16-bit segment base - is what let the 8086 address a full 1 MB space using only 16-bit registers, while the variety of base/index/displacement combinations gave compilers efficient single-instruction access patterns for arrays, structures, and stack frames, patterns that are directly inherited by later x86 addressing modes.
Default Segment Associations
Each addressing mode is tied to a default segment register unless overridden. BX, SI and DI default to the Data Segment (DS); BP defaults to the Stack Segment (SS), which is why based addressing using BP is the natural way to access parameters and local variables on the stack within a subroutine. The instruction pointer (IP) always works with the Code Segment (CS), and string instructions using DI always work with the Extra Segment (ES), regardless of any other override, which matters for instructions like MOVS that copy between two different segments simultaneously using SI (source, DS) and DI (destination, ES). A segment override prefix byte can force any instruction to use a non-default segment register when required, giving the programmer full control when the default associations do not match the intended memory layout.