Architecture, Programming, and Interfacing (8086 to Pentium)
Addressing Mode of 8086
Prof. Dr. Shamim Akhter
Professor, Computer Science and Engineering (CSE)
Addressing Mode
• Identify the location and value of an operand.
MOV AX, 23H
Destination Source
Operand Operand
Register Addressing Base Plus Index Addressing
Immediate Addressing Register Relative Addressing
Direct Addressing Base Relative Plus Index Addressing
Register Indirect Addressing Scaled Index Addressing
RIP Relative Addressing
8086 Instruction Format
Low High Low Data High Data
Disp/Data Disp/Data
• Opcode field (6-bit): Specifies the operation, such as add, subtract, or move,
that is to be performed.
• Register direction bit (D bit): Tells whether the register operand specified by
register in byte 2 is the source or destination operand. Logic 1 in this bit position
indicates that the register operand is a destination operand, and logic 0
indicates that it is a source operand.
• Data size bit (W bit): Specifies whether the operation will be performed on 8-bit
or 16-bit data. Logic 0 selects 8 bits and 1 selects 16 bits as the data size.
• The register filed (reg.) is 3-bit. It is used to identify the register for the first
operand, which is the one that was defined as the source or destination by
the D bit in byte 1.
• The 2-bit mod field and 3-bit r/m field together specify the second operand.
• Encoding for these two fields is shown in the following table.
• Mod indicates whether the operand is in a register or memory.
• Note that in the case of a second operand in a register, the mod field is always
11. The r/m field, along with the W bit from byte1, selects the register.
Addressing Modes
• Data Addressing Mode
No memory reference to fetch data
Faster processing
Operand is in register
1. Register Addressing
– Transfer a copy of a byte/word from the source register to
the destination register
– Operand is in general purpose register
MOV AX, BX
MOV ECX, EBX
MOV RAX, RBX
MOV ES, DS
MOV BL, DX NOT ALLOWED
MOV CS, AX
Encode MOV BL, AL
Move Opcode: MOV is 100010
Addressing Modes
2. Immediate Addressing
– Immediate implies data immediately follow
hexadecimal opcode in the memory
– Operand is constant data and part of instruction
MOV AL, 23H
MOV AX, 3456H
• MOV AX, ‘AB’ -> ASCII characters are stored as BA
• MOV AH,1 not allowed in 64 bit but allowed in 32 and 16
bits
Immediate Addressing
MOV opcode 1011
Format:1011wrrr data
• MOV AX, 5001H
1011 1 000 00000001 01010000
• MOV BX, 23H
1011 1 011 0010 0011 00000000
• MOV Cl, 23H
1011 0 001 0010 0011
Memory Addressing Mode
Direct and
Displacement
Register Indirect
Memory
Addressing Base Index
Mode
Register Relative
Operand is in Memory
Register based
Indexed
Addressing Modes
• Direct Addressing
– Operand is the address of the internal data memory
MOV AL, [1234H]
MOV AX, LIST
MOV RAX, HELLO
• Displacement Addressing
MOV AL, DS:[1234H]
– Any segment register can be used.
Direct and Displacement Addressing
MOV instruction format:100010dw oorrrmmm disp
[Not accumulator register]
MOV instruction format:101000dw disp
[Accumulator register]
• MOV AX, [1234H]
1010 0011 0011 0100 0001 0010
• MOV BL, [1234H]
1000 10 10 00 011 110 0011 1000 0001 0010
• MOV BX, [1234H]
.data • 1000 10 11 00 011 110 0011 0100 0001 0010
array DW 1234H
.code • MOV [1234H], BX
mov BX, array • 1000 10 01 00 011 110 0011 0100 0001 0010
ret
Addressing Modes
• Register Indirect addressing
– Data to be addressed at any memory location
through an offset address held any base (BP, BX) or
index (SI, DI) register.
Default
Segment is MOV AX, [BX]
Data segment
(DS) MOV ECX, [EBX]
BP points to stack
MOV AX, [BP] segment (SS)
MOV [DI], [BX] Memory-to-memory transfer NOT allowed
Assembler can’t determine the location size – byte,
MOV BYTE PTR [DI], 10H word, double word
Thus PTR directives are used
MOV AX, [BX]
MOV format 100010dw oorrrmmm disp
• MOV AX, [BX]
1000 10 11 00 000 111…
• MOV CX, [BX]
100010 11 00 001 111…
Addressing Modes
• Base-Plus-Index Addressing
– Similar to indirect addressing because it indirectly
addresses memory data.
MOV DX, [BX+DI]
MOV DL, [EAX+EBX]
MOV DX, [BX][DI]
MOV CH, [BP+SI]
MOV [BX+SI], SP
MOV [EAX+EBX], ECX
MOV ARRAY[DI], BL
Addressing ARRAY data with
Register Addressing
.data
array DW 1234H,1243H, 1111H
.code
mov DI, 8
mov BX, array
mov [BX+DI], BL
ret
MOV DX, [BX+DI]
MOV format 100010dw oorrrmmm disp
• MOV DX, [BX+DI]
100010 11 00010001…
MOV [BX+DI], BL
.data
100010 00 00 011 001…
array DW 1234H,1243H, 1111H
.code .data
mov DI, 8 array DW 1234H,1243H, 1111H
mov BX, array .code
mov DI, 8
mov DX, [BX+DI]
mov BX, array
ret mov [BX+DI], BL
ret
Addressing Modes
• Register Relative Addressing
– Similar to base-plus-index addressing and displacement
addressing.
MOV AX, [BX+1000H]
8-bits displacement
(sign extended) 16 bits displacement
(sign extended) 32 bits displacement
MOV format 100010dw oorrrmmm disp
• MOV DX, [BX+08H]
100010 11 01010111 00001000
.data
array DW 1234H,1243H, 1111H
.code
mov DI, 8
mov BX, array
mov DX, [BX+08H]
ret
Examples of register relative
addressing
Assembly Language Size Operation
MOV AX, [DI+100H] 16 Copies the word contents of the data segment
bits memory location addressed by DI plus 100H into AX
MOV ARRAY[SI], BL 8 bits Copies BL into the data segment memory location
addressed by ARRAY plus SI
MOV LIST[SI+2], CL 8 bits Copies CL into the data segment memory location
addressed by the sum of LIST, SI and 2
MOV DI, [EAX+10H] 16 Copies the word contents of the data segment
bits memory location addressed by EAX plus 10H into DI
MOV ARRAY[EBX], EAX 32 Copies EAX into the data segment memory location
bits addressed by ARRAY plus EBX
MOV ARRAY[RBX], AL 8 bits Copies AL into the memory location ARRAY plus RBX
(64-bit mode)
Base Relative Plus Index Addressing
• Similar to base-plus-index addressing, but it
adds displacement
MOV AX, [BX+SI+100H]
MOV AX, [BX+SI+100H]
mov DX, [BX+DI+3H]
• MOV format 100010dw oorrrmmm disp
• 100010 11 01 010 001 00000011
.data
array DW 1234H,0000H, 0000H
.code
mov DI, 1H
mov BX, array
mov DX, [BX+DI+3H]
ret
Addressing Modes
• Scaled-Index Addressing(80386 to above)
– Two 32-bit registers (Base and Index)
• 2nd register (index) is multiplied by a scaling factor
• Scaling factor can be 1x, 2x(word), 4x(double word), or
8x (quadword)
MOV AX, [EDI+2*ECX] --word addressing
ECX has 00000001H increase ECX by scaled 2
MOV EAX, ARRAY [4*ECX] ---Double word addressing
Addressing Modes
• RIP Relative Addressing
– Uses 64-bit instruction pointer register in the 64-
bit mode to address a linear location in the flat
memory model.