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:
- Immediate Addressing Mode: The operand is part of the instruction itself.1MOV AX, 10ABH ; Immediate 16-bit constant loaded into register AX2MOV BL, 25H ; Immediate 8-bit constant loaded into register BL
- Register Addressing Mode: The operand is contained in an 8-bit or 16-bit general register. No memory bus access is required.1MOV AX, BX ; Copy 16-bit word from BX to AX2MOV DH, CL ; Copy 8-bit byte from CL to DH3ADD SI, DI ; Add 16-bit index DI to SI
- Direct Addressing Mode: The 16-bit offset of the operand is explicitly provided inside the instruction.1MOV AX, [5000H] ; Read 16-bit word at DS:5000H into register AX2MOV [7000H], CX ; Store word from CX into DS:7000H
- Register Indirect Addressing Mode: The operand's offset is stored in register or .1MOV AX, [BX] ; Default segment: DS -> Physical = (DS * 10H) + BX2MOV DX, [BP] ; Default segment: SS -> Physical = (SS * 10H) + BP
- Based Addressing Mode: The offset is the sum of a base register ( or ) and an 8-bit or 16-bit displacement:1MOV AX, [BX + 04H] ; Access structure field relative to base record pointer2MOV CX, [BP + 06H] ; Access stack parameter relative to stack frame base
- Indexed Addressing Mode: The offset is the sum of an index register ( or ) and a displacement:1MOV AX, [SI + 2000H] ; Access array element at index SI from array base
- Based Indexed Addressing Mode: The offset is the sum of one base register and one index register:1MOV AX, [BX + SI] ; Access 2D array row BX and column SI2MOV DX, [BP + DI] ; Stack-based 2D lookup
- Based Indexed with Displacement: Combines base, index, and an explicit offset: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 (source) and (destination), automatically updating pointers based on the Direction Flag ():
MOVSB/MOVSW: Move byte/word from to .CMPSB/CMPSW: Compare string elements and set flags.SCASB/SCASW: Scan string for value matching Accumulator .LODSB/STOSB: Load string byte into , or store into .- Repeat Prefixes (
REP,REPE/REPZ,REPNE/REPNZ): Repeats the string instruction until or the zero condition terminates.
2. The XLAT (Translate) Instruction
XLAT implements single-cycle lookup table conversion. It replaces the byte in with the byte located at offset in the data segment:
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 and jumps to the target label if , 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 ( bits) per item. Example:SCORES DB 95, 87, 92orMSG DB 'HELLO$', 0.DW(Define Word): Allocates 1 word ( bits = 2 bytes) in little-endian order. Example:TABLE DW 1234H, 5678H.DD(Define Doubleword): Allocates 2 words ( bits = 4 bytes). Often used for 32-bit segment:offset pointers.DQ(Define Quadword): Allocates 4 words ( bits = 8 bytes), used for double-precision floating-point numbers.DT(Define Tenbytes): Allocates 10 bytes ( bits), used for packed BCD numbers or 8087 80-bit extended precision floats.DUPOperator: Duplicates a value times. Example:BUFFER DB 100 DUP(?)reserves an uninitialized 100-byte buffer.
2. Segment Definition and Register Association
SEGMENTandENDS: 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:1 ASSUME CS:CODE_SEG, DS:DATA_SEG, SS:STACK_SEG
3. Procedure and Scope Directives
PROCandENDP: Enclose a procedure or subroutine.NEARvs.FAR:NEARspecifies intra-segment calling (only is pushed/popped, using single-wordRET);FARspecifies inter-segment calling (both and are pushed/popped, using two-wordRETF).
4. Memory and Pointer Modifiers
ORG(Origin): Sets the location counter to a specific offset (e.g.ORG 100Hfor DOS.COMfiles).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], 5is ambiguous;MOV BYTE PTR [BX], 5orMOV WORD PTR [BX], 5explicitly specifies operand width.