Anda di halaman 1dari 48

8086 Addressing Modes

Lecture 6
8086 Instruction
An instruction consists of an opcode and an operand.
The operand may reside in the accumulator, in a general purpose register,
in a memory location, in I/O port and in the instruction itself.
An operand can be a byte or word.
Word data can be located at odd or even byte boundaries of memory.
Definition of addressing mode?

The manner in which an operand is specified (or

referred to) in an instruction.
The following are the different addressing modes of
Register operand addressing.
Immediate operand addressing.
Memory operand addressing.
Memory Addressing
The 80x86 memory addressing modes provide flexible access to
memory, allowing you to easily access variables, arrays,
records, pointers, and other complex data types.
The processor uses two memory accesses/cycles to read 16-bit
word located at odd byte boundaries. Reading word data from
even byte boundaries requires only one memory access/cycles
The 8086 Logical Organization The 8086 memory Physical

0000H 12 Byte =12H Address Address

0001H 34 Word =
5634H 00001H 34 12 00000H
0002h 56

0003H 78 Byte = 78H 00003H 78 56 00002H

0004H 9A Word =
BC9A 00005H BC 9A 00004H
0005H BC
There are 7 types of addressing mode in 8086
Register Indirect
Based with displacement
Indexed with displacement
Based Indexed with displacement
Register Addressing Mode

The operand (byte or word) to be accessed is specified as residing in an internal

register(GPRs) of the 8086, an example of an instruction that uses this addressing mode
This stands for move the contents of BX, the source operand, to AX, the destination
operand. Both the source and destination operands have been specified as the content of
the internal registers of the 8086.
All registers may be used except IP
EA = R EA = Effective Address (EA) for one location which contain reference operand
R = Address field content in instruction which refer to register (R)

MOV BX, DX ; copies the 16 bit contents of DX to BX

MOV AL, BL ; copies the 8-bit contents of BL to AL
MOV SI, DI ; copies the contents of DI to SI
MOV DS, AX ; change the starting address of DS
MOV BL, BX ; Not permitted (mixed sizes)
MOV CS, AX ; Not permitted (CS cannot be modified directly, use far JMP or
MOV ES, DS ; Not permitted (segment to segment not allowed)
Immediate Addressing Mode
If a source operand is part of the instruction instead of the contents of a register or
memory location, it represents what is called an immediate operand and is accessed
using the immediate addressing mode.
Typically, immediate operands represent constant data (8-bit or 16-bit). Immediate
operands can be either a byte or word of data. In the instruction
MOV AL, 015H
The source operand 15H is an example of a byte-wide immediate source operand. Note
that the value of the immediate operand must always be preceded by a zero.
Can be used to load information to any registers except the segment registers and flag

MOV AL, 0AH ; Loads 0AH into AL

MOV BX, 1000H ; Loads 1000H into BX
MOV CL ,A ; Loads the ASCII code for A (65 in Decimal) into CL
MOV AL, 2AAH ; Not allowed as the data exceeds the length of the
destination register (use register indirect addressing)
Invalid example
MOV DS, 0123H
This problem can be overcome by loading 0123H to one general purpose register and
then the register value is copied to segment register as the following:
MOV AX, 0123H
Direct Addressing Mode
The instruction operand specifies the memory address (16-bit memory address offset)
where data is located.
Direct addressing differs from immediate addressing in that the locations following the
instruction opcode hold an effective memory address (EA) instead of data.
This effective address is a16-bit offset of the storage location of the operand from the
current value in the data segment (DS) register.
EA is combined with the contents of DS in the BIU to produce the physical address
(PA)for its source operand is
This stands for move the contents of the memory location which is offset by
BETA from the current value in DS into internal register CX.
Notice that the value assigned to constant
BETA is 1234H.
PA = 02000H + 1234H = 03234H
Source operand is the address not immediate data (written in [ ])
org 100h
BETA equ 1234h
mov [BETA], 2222h
mov cx, [BETA]

MOV DL, [2400H]

Effective Address given is = 2400h. If DS content is 2000 therefore physical
address is
Physical Address = Segment Address + Effective Address
= 20000H+2400H=22400H
Assume DS = 1000H, ES = 2000H, FRED = 4567H
MOV AX, [0020h] ; loads contents at address 10020H and 10021H into AL
and AH respectively
MOV [1234H], AL ; copies al to 11234H
MOV ES:[1234H], AL ; copies al to 21234H
MOV FRED , AL ; copies AL to 14567H (offset is calculated by the
Array implementation using direct addressing modes
org 100h
num db 1h,2h,3h,4h,5h
mov al, num[0]
Register indirect addressing mode.
The address of source or destination is represented by contents of a register.
Register indirect addressing is similar to direct addressing in that an effective
address is combined with the contents of DS to obtain a physical address.
However, it differs in the way the offset is specified.
This time EA resides in either a base register or index register within the 8086.
The base register can be either BX or BP and the index register can be SI or DI.
R= content for address
field in instruction
which referred to
This instruction moves the contents of the memory
location offset by the value of EA in SI from the
current value in DS to the AX register.
SI contains 1234H and DS contains 0200H.
PA = 02000H + 1234H = 03234H

mov al, [bx]

mov al, [bp]
mov al, [si]
mov al, [di]
It is often used to access data table from memory

Assume BX = 0222H, DS = 1000H, SS = 2000H, BP = 0111H

MOV CX, [BX] ; copies a word from 10222H and 10223H to CX
MOV [BP], DL ; copies a byte from register DL to 20111H
Note: BP defaults to SS
org 100h
num db 1h,2h,3h,4h,5h
mov al, num[0]
mov bx, 4
mov al, num[bx]
Based Addressing Mode
This type of addressing mode allows access to list items and other data
structure when the offset to a particular item is known at assembly time,
but the base address of the data structure must be computed at run time.
In the based addressing mode, the physical address of the operand is
obtained by adding a direct or indirect displacement (8-bit or 16-bit) to the
contents of either BX or BP and the current value in DS and SS,
The Fig shows the utility of using either BX/BP or displacement.
The figure shows a data structure starting from Element 0 to Element n.
Inserting a zero value for displacement would ensure accessing Element 0
of the structure.
For accessing different elements within the same data structure, all that is
to be done is to change the value of displacement.
Whereas, to access the same element is another data structure the value of
the base register has to be changed, keeping the value of displacement same
as before.
A MOV instruction that uses based addressing to specify the location of its
destination operand is as follows:
DS = 0200h, BX = 1000H, BETA = 1234H

BETA equ 1234h

mov ax, 0200h
mov ds, ax
mov bx , 1000h
mov ax, 0BEEDh

As shown the fetch and execution of this instruction causes the BIU to
calculate the physical address of the destination operand from the contents
of DS, BX, and the direct displacement.
The result is PA = 02000H + 1000H + 1234H = 04234H
Effective Address = [Base register] + displacement (i.e [bx] + disp or [bp]
+ disp)
Indexed addressing works identically to the based addressing, it uses the contents of one
of the index registers (SI and DI), instead of BX or BP, in the generation of the physical
address, here is an example:
The example shows the result of executing the MOV instruction.
First the physical address for the source operand is calculated from DS, SI, and the
direct displacement.
PA = 02000H + 2000H + 1234H= 05234H
Then the byte of data stored at this location, which is BEH is read into lower byte AL of
the accumulator register.

MOV AX , [SI] + DISP ; data available at an offset address stored in SI and DS

MOV DX , [SI] + 5
MOV CL , [DI] +20
If DS = 1000H, SI = 222H, DI = 111H
MOV [DI-1], BL ; stores the content of BL to 10110H
MOV BX, [SI+ 1000H] ;loads BL with the contents of 11222H and BH with the
contents of 11223H
Based Indexed Addressing Mode
Combining the based addressing mode and the indexed addressing mode together
results in a new, more powerful mode known as based indexed addressing.
Consider an example of a MOV instruction using this type of addressing.
This addressing mode is used to access a two dimensional (m n) array,
The displacement, having a fixed value, locates the starting position of the array in the
memory while the base register specifies one coordinate (say m) and index register the
other coordinate (say n).
Any position in the array can be located simply by changing the values in the base and
index registers.
An example of this mode of addressing is as follows:
An example of executing this instruction is illustrated
The address of the source operand is calculated as PA = 02000H + 1000H + 1234H +
2000H = 06234H
Execution of this instruction causes the Value stored at this location to be written into
The contents of a base register (BX or BP) is added to the contents of an index register
(SI or DI), the resulting value is a pointer to location where data resides.
As default, segment address is obtained from DS or ES except for BP register which is
obtained from SS

Mov ax , [bx][SI]+ disp

Mov al
mov al, [bx][si]
mov al, [bx][di]
mov al, [bp][si]
mov al, [bp][di]
String Addressing Mode
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) to point to the next byte or word.
Example :
If [DF] = 0, [DS] = 2000 H, [SI] = 0500, [ES] = 4000, [DI] = 0300
Source address : 20500, assume it contains 38
Destination address = ES: DI = 40300, assume it contains 45
After executing MOV SB,
[40300] = 38
[SI] = 0501 incremented
[DI] = 0301
The string instructions of the 8086's instruction set automatically use the
source and destination index registers to specify the effective addresses of
the source and destination operands, respectively.
The move string instruction MOVSB is an example.
Notice that neither SI nor DI appears in the string instruction, but both are
used during its execution.
D-Direction Flag
This is used by string manipulation instructions.
If this flag bit is '0', the string is processed beginning from the lowest address
to the highest address, i.e. autoincrementing mode.
Otherwise, the string is processed from the highest address towards the
lowest address, i.e. autodecrementing mode.
D-Direction Flag
mov si, 0500h
mov di, 0300h
mov ax, 2000h
mov ds, ax
mov ax, 4000h
mov es, ax
mov [si],38
mov es:[di],45