Skip to content
Advanced Microprocessor

8086 Addressing Modes & Advanced String Operations

Effective address formulas, based/indexed modes, XLAT lookup table conversion, and REP string manipulation primitives.

Knova editors11 min readQuick checkSources

8086 Addressing Modes and Advanced Instruction Set

The 8086 provides a versatile set of addressing modes to calculate the Effective Address (EA) of memory operands, supporting high-level language data structures like multi-dimensional arrays, records, and stack frames.

The Addressing Modes of 8086

The Effective Address (EA) is the 16-bit offset of the operand within its logical segment. In the 8086, the EA is computed by combining up to three components:

EA=Base Register (BX or BP)+Index Register (SI or DI)+Displacement (8-bit or 16-bit)EA = \text{Base Register } (BX \text{ or } BP) + \text{Index Register } (SI \text{ or } DI) + \text{Displacement } (8\text{-bit or } 16\text{-bit})
  1. Immediate Addressing Mode: The operand is part of the instruction itself.
    assembly
    1MOV AX, 10ABH ; Immediate 16-bit constant loaded into register AX
    2MOV BL, 25H ; Immediate 8-bit constant loaded into register BL
  2. Register Addressing Mode: The operand is contained in an 8-bit or 16-bit general register. No memory bus access is required.
    assembly
    1MOV AX, BX ; Copy 16-bit word from BX to AX
    2MOV DH, CL ; Copy 8-bit byte from CL to DH
    3ADD SI, DI ; Add 16-bit index DI to SI
  3. Direct Addressing Mode: The 16-bit offset of the operand is explicitly provided inside the instruction.
    EA=Displacement  ⟹  Physical Address=(DS×10H)+DisplacementEA = \text{Displacement} \implies \text{Physical Address} = (DS \times 10\text{H}) + \text{Displacement}
    assembly
    1MOV AX, [5000H] ; Read 16-bit word at DS:5000H into register AX
    2MOV [7000H], CX ; Store word from CX into DS:7000H
  4. Register Indirect Addressing Mode: The operand's offset is stored in register BX,BP,SI,BX, BP, SI, or DIDI.
    EA=[BX] or [BP] or [SI] or [DI]EA = [BX] \text{ or } [BP] \text{ or } [SI] \text{ or } [DI]
    assembly
    1MOV AX, [BX] ; Default segment: DS -> Physical = (DS * 10H) + BX
    2MOV DX, [BP] ; Default segment: SS -> Physical = (SS * 10H) + BP
  5. Based Addressing Mode: The offset is the sum of a base register (BXBX or BPBP) and an 8-bit or 16-bit displacement:
    EA=[BX]+disp(Segment: DS)orEA=[BP]+disp(Segment: SS)EA = [BX] + \text{disp} \quad (\text{Segment: } DS) \quad \text{or} \quad EA = [BP] + \text{disp} \quad (\text{Segment: } SS)
    assembly
    1MOV AX, [BX + 04H] ; Access structure field relative to base record pointer
    2MOV CX, [BP + 06H] ; Access stack parameter relative to stack frame base
  6. Indexed Addressing Mode: The offset is the sum of an index register (SISI or DIDI) and a displacement:
    EA=[SI]+disporEA=[DI]+dispEA = [SI] + \text{disp} \quad \text{or} \quad EA = [DI] + \text{disp}
    assembly
    1MOV AX, [SI + 2000H] ; Access array element at index SI from array base
  7. Based Indexed Addressing Mode: The offset is the sum of one base register and one index register:
    EA=[BX or BP]+[SI or DI]EA = [BX \text{ or } BP] + [SI \text{ or } DI]
    assembly
    1MOV AX, [BX + SI] ; Access 2D array row BX and column SI
    2MOV DX, [BP + DI] ; Stack-based 2D lookup
  8. Based Indexed with Displacement: Combines base, index, and an explicit offset:
    EA=[BX or BP]+[SI or DI]+dispEA = [BX \text{ or } BP] + [SI \text{ or } DI] + \text{disp}
    assembly
    1MOV AX, [BX + SI + 10H] ; Access record element in array of structures

Specialized 8086 Instruction Features

1. String Manipulation Primitives

The 8086 provides dedicated high-speed string instructions that operate on memory arrays using DS:SIDS:SI (source) and ES:DIES:DI (destination), automatically updating pointers based on the Direction Flag (DFDF):

  • MOVSB / MOVSW: Move byte/word from [DS:SI][DS:SI] to [ES:DI][ES:DI].
  • CMPSB / CMPSW: Compare string elements and set flags.
  • SCASB / SCASW: Scan string for value matching Accumulator AL/AXAL/AX.
  • LODSB / STOSB: Load string byte into ALAL, or store ALAL into [ES:DI][ES:DI].
  • Repeat Prefixes (REP, REPE/REPZ, REPNE/REPNZ): Repeats the string instruction until CX=0CX = 0 or the zero condition terminates.
assembly
1; High-speed memory block copy of 100 bytes using REP MOVSB
2 LEA SI, SOURCE_BUF ; SI = Offset of source buffer
3 LEA DI, DEST_BUF ; DI = Offset of destination buffer
4 MOV CX, 100 ; CX = String length counter
5 CLD ; Clear DF (auto-increment SI & DI)
6 REP MOVSB ; Repeat copy until CX reaches 0

2. The XLAT (Translate) Instruction

XLAT implements single-cycle lookup table conversion. It replaces the byte in ALAL with the byte located at offset BX+ALBX + AL in the data segment:

AL←[DS:BX+AL]AL \leftarrow [DS:BX + AL]

This instruction is widely used for code conversions such as ASCII to 7-Segment displays or EBCDIC to ASCII.

3. Loop Control Instructions

LOOP target automatically decrements register CXCX and jumps to the target label if CX≠0CX \neq 0, eliminating separate decrement and conditional jump instructions.

8086 Assembler Directives

Assembler directives are pseudo-instructions directed to the assembler program (e.g., MASM, TASM) rather than the CPU. They generate no machine code directly, but guide memory allocation, segment structure, and symbol resolution.

1. Data Definition Directives

  • DB (Define Byte): Allocates 1 byte (88 bits) per item. Example: SCORES DB 95, 87, 92 or MSG DB 'HELLO$', 0.
  • DW (Define Word): Allocates 1 word (1616 bits = 2 bytes) in little-endian order. Example: TABLE DW 1234H, 5678H.
  • DD (Define Doubleword): Allocates 2 words (3232 bits = 4 bytes). Often used for 32-bit segment:offset pointers.
  • DQ (Define Quadword): Allocates 4 words (6464 bits = 8 bytes), used for double-precision floating-point numbers.
  • DT (Define Tenbytes): Allocates 10 bytes (8080 bits), used for packed BCD numbers or 8087 80-bit extended precision floats.
  • DUP Operator: Duplicates a value NN times. Example: BUFFER DB 100 DUP(?) reserves an uninitialized 100-byte buffer.

2. Segment Definition and Register Association

  • SEGMENT and ENDS: Enclose a logical segment block (e.g. DATA_SEG SEGMENT ... DATA_SEG ENDS).
  • ASSUME: Informs the assembler which logical segment name belongs to which segment register. Example:
    assembly
    1 ASSUME CS:CODE_SEG, DS:DATA_SEG, SS:STACK_SEG

3. Procedure and Scope Directives

  • PROC and ENDP: Enclose a procedure or subroutine.
  • NEAR vs. FAR: NEAR specifies intra-segment calling (only IPIP is pushed/popped, using single-word RET); FAR specifies inter-segment calling (both CSCS and IPIP are pushed/popped, using two-word RETF).

4. Memory and Pointer Modifiers

  • ORG (Origin): Sets the location counter to a specific offset (e.g. ORG 100H for DOS .COM files).
  • EQU (Equate): Defines a symbolic constant without allocating memory (e.g. MAX_COUNT EQU 50).
  • OFFSET: Returns the 16-bit displacement of a variable from the base of its segment (e.g. MOV SI, OFFSET BUFFER).
  • PTR (Pointer Operator): Resolves operand size ambiguity. Example: MOV [BX], 5 is ambiguous; MOV BYTE PTR [BX], 5 or MOV WORD PTR [BX], 5 explicitly specifies operand width.
Try it
Default Segment Binding: When an instruction uses Base Pointer register BPBP (e.g. MOV AX, [BP + 4]), which segment register is used by default to generate the physical address?

Sources

  1. 1.Intel 8086 Microprocessor Datasheet · reference · Intel (opens in a new tab)

Was this chapter useful?

Editors read every answer.

Star this chapter

Each star goes once to every reader who improved this chapter.

Finished reading?

Mark it to keep your place in the course.