Chapter Three
8086 Addressing
Modes
1
Addressing mode
Addressing mode indicates a way of locating data/operands or the
manner in which a microprocessor specifies the address of the
operands in an instruction .
The addressing modes describe the types of operands and the way
they are accessed for executing an instruction.
In this chapter, MOV (move data) instruction is used to describe the
addressing modes.
Since the MOV instruction is common and flexible , it provides a
basis for the explanation of the addressing modes.
The MOV instruction transfers bytes/words of data between registers
or between registers and memory in the 8086 through 80286.
2
MOV instruction always copies the source data into the
destination .
Also, note that the flag registers remain un-affected by most
data transfer instructions.
Notice that a comma always separates the destination from the
source in an instruction.
3
When 8086 executes an instruction, it performs the
specified function on data, called as the operands.
These operands may
be a part of the instruction
reside in one of the internal registers of the
microprocessor
be stored at an address in memory
4
8086 has 12 basic addressing modes
The various 8086 addressing modes can
be classified into 5 groups.
5
Addressing Modes for accessing Immediate and
Register Data (Register And Immediate Modes)
Addressing Modes for accessing Data in Memory
(Memory Modes)
Addressing Mode for accessing I/O Parts (I/O
Modes)
Relative Addressing Mode.
Implied Addressing Mode.
6
7
• Register addressing mode is the most common
form of data addressing .
• This mode specifies the source operand, destination
operand or both to be contained in an 8086 register.
• In this mode, data is stored in a register and is
referred by a particular register. All the registers
except IP, may be used in this mode.
• E.g. MOV DX,CX moves the 16 bit contents of CX
into DX.
• MOV CL,DL moves 8 bit contents of DL into CL
• MOV BH,CX is an illegal instruction.
8
• Segment register - to - Segment register, MOV
instruction is not allowed.
• The instruction MOV BX,CX will copy the contents
of CX into BX register. Also this will erase the old
contents of register BX, but the contents of CX will
remain unchanged.
• The contents of the destination register or
destination memory location will change for all type
of MOV instructions except the CMP and TEST
instructions.
9
• In immediate mode, 8 or 16 bit data can be specified as
part of the instruction.
• E.g: MOV CL,03H (which moves 8 bit data into CL)
• E.g: MOV DX,0502H (which moves 16 bit data 0502H into DX)
• E.g: MOV BH, ‘A’ (moves an ASCII code of A (41H)into BH)
• In both of the above MOV instruction , the destination operand is
in register mode.
• Even though the immediate mode specifies data with the
instruction, these immediate data must be located in the
memory addressed by the 8086 CS and IP registers. This is
because these data are considered as part of the instruction.
10
• A constant such as “VALUE” can be defined
by the assembler EQU (means EQUATE)
directive such as VALUE EQU 35H.
• An 8086 instruction with immediate mode
such as MOV BH, VALUE can then be used
to load 35H into BH.
11
12
• EU must use BIU in order to access memory
operands since EU cannot access memory operands
directly. For e.g.: when the EU needs to access a
memory location (8086 must use a segment register
whenever it accesses the memory) it sends an offset
value to the BIU. This offset is called the Effective
Address (EA).
• EA is the displacement of the desired location from
the segment base.
• Then BIU will generate 20 bit physical address with
the segment register by adding 16 bit EA to it.
13
Direct Addressing Mode
Register Indirect Addressing Mode.
Based Address Mode.
Indexed Address Mode.
Based Indexed Address Mode.
String Address Mode
14
• Transfers data between a memory location and a register.
• In this mode, 16 bit EA is taken directly from the
displacement field of the instruction.
• This EA or displacement is the distance of the memory
location from the current value in the data segment(DS)
register in which the data are stored.
• Consider MOV AX, [5000H]
• Here data resides in a memory location in the data
segment, whose effective address may be computed using
5000H as the offset address and the content of DS as
segment address. The Physical address, here, is 10H* DS +
5000H
15
• Another example of 16 bit read from memory,
Consider MOV CX , START.
The source is in direct addressing mode.
This instruction moves the contents of memory location which is
offset by START from the current DS value into CX
The 16 bit value can be assigned to the offset START by the programmer
using an assembler pseudo instruction like DW [Define Word] or
DB[Define Byte]. Suppose it is 0040H.
(Suppose, DS = 3050H) then BIU generates the 20 bit physical address
30540H on the 8086 address line and then initiates a memory read cycle
to read the 16 bit data from memory location starting at 30540H
The memory logic, places the contents of locations 30540H and 30541H
on the 8086 data pins.
16
• An e.g. of 8 bit read from memory
MOV CH, START
• If DS = 3050H and the value of START is 0040H
then 8 bit content of memory location 30540H is
moved to register CH.
17
• An e.g. of 16 bit write to memory
• MOV START, BX
• With DS =3050H. If the value of START is
0040H, the MOV instruction moves BX to
location 30540H.([BL] to 30540H and [BH] to
30541H )
• An e.g. of 8 bit data write
• MOV START , BL.
18
In register indirect addressing, the offset address held
in any of the following registers.
The offset address of data can be either in BX, BP or
SI/DI register.
The default segment is either DS/ES or SS.
By default, the Data Segment (in register indirect
addressing mode) uses BX, DI, or SI to address memory.
If BP addresses memory, the Stack Segment is used by
default.
19
• Normally, in this mode, the EA is specified
with a pointer register or an index register.
• The pointer register can be either base
register(BX) or base pointer register(BP).
• Index register can be either source index(SI)
register or destination index(DI) register.
• 20 bit physical address is computer using DS
and EA.
20
Example MOV AX, [BX]
• In the above example, the source operand
is in register indirect mode , while the
destination operand is in register mode.
• Here the data is present in a memory location
in DS whose offset address is in BX.
• The Physical address of the data is given as
10H*DS+[BX]
21
Another E.g: MOV[DI],BX.
• The source operand is in register mode , while the
destination operand is in register indirect mode.
• The above instruction moves the 16 bit content of BX into a
memory which is offset by the value, (EA) specified in DI
with the current DS.
• If DS=5004H and DI=0020H and BX=2456H,then after MOV
[DI],BX .
• Content of BX (2456H) is moved to memory location
50060H . (50040H + 0020H = 50060H)
• ie, BL to 50060H and BH to 50061H
22
• In some cases, indirect addressing requires specifying the
size of the data. For this purpose, special assembler
directives like BYTE PTR, WORD PTR are being used in
an instruction. These directives indicate the size of the
memory data addressed by the memory pointer (PTR).
• For eg: MOV AL,[DI] is clearly a byte sized instruction
• But MOV [DI], 10H is an ambiguous. The assembler cant
determine the size of the 10H.
• The instruction MOV BYTE PTR [DI], 10H clearly
designates the location addressed by DI as a byte sized
memory location.
• Likewise, MOV WORD PTR [DI],1020H clearly
identifies the memory location as word sized one.
23
• In this mode, EA is obtained by adding a
displacement value to the contents of BX / BP.
• The segment registers used are DS and SS.
• When the data is accessed, the 20-bit physical
address is computed from BX and DS.
• When the stack is accessed, 20 bit physical address
is computed from BP and SS.
24
Consider MOV AX , START[BX]
• The source operand in the above instruction is in based mode.
• EA is obtained by adding the value of START and [BX].
• The 20-bit physical address is computed from DS &
EA.
• Consider the displacement START is 1000H.
If BX contains the value 0100H and DS= 0200H ,the
Physical address will be 10H * DS+1100H
• The following diagram will depicts the transfer of 16-
bit data to the register AX
25
26
Indexed Addressing Mode
• In this mode, the effective address(EA) is calculated by
adding the displacement and the contents of SI or DI
• Eg; MOV BH, START [SI]
• Moves the 8-bit contents of 20 bit address computed
from the displacement (START, SI) and DS into BH.
• The displacement (here it is START) is provided by the
programmer using the assembler pseudo-instruction
such as EQU.
27
• Indexed addressing mode can be used to access a
single table/array.
• The displacement can be the starting address of
the table/array.
• The contents of SI or DI can then be used as an
index from the starting address to access a
particular element in the table.
28
• Consider the following code, where START specifies the
displacement
MOV SI , 10H
MOV AL , START[SI]
MOV SI , 20H
MOV START[SI],AL
can transfer the contents of array element 10H into array element
20H.
29
Based Indexed Addressing Mode
A least used addressing mode.
This addressing mode is too complex for frequent use in a
program
In this mode, the EA is computed by adding a base register
(BX or BP), an index register (SI/DI) and a displacement
E.g.: MOV ALPHA [SI] [BX], CL
If BX = 0200H, value of ALPHA = 08H
SI = 1000H and DS = 3000H
then 8-bit contents of CL is moved to 20 bit physical
address (DS+EA)
30
The 20 bit physical address (DS+EA)=31208H, is calculated as below ,
EA 0200H + BX
1000H + SI
08H displacement
---------------
1208H
Now, DS + EA 30000H +
1208H
---------------
31208H
31
• Consider the instruction,
MOV AX , ALPHA [BX][SI]
where ALPHA=100H, BX=0020H, SI= 0010H and DS=1000H
The above MOV instruction will work as the following
figure shows.
32
33
String Addressing Mode
• This mode uses index registers.
• The string instructions automatically assume SI to point to the
first byte (or word) of the source operand and DI to point the
first byte (or word) of the destination operand.
• The contents of SI and DI are automatically incremented (by
clearing DF to 0 using CLD instruction) or decremented (by
setting DF to 1 using STD instruction) to point to the next byte
(or word).
• The segment register for the source is DS and the segment
register for the destination must be ES.
34
E.g: Consider the instruction MOVS BYTE
Case :- with CLD instruction. [DF = 0] (automatically increments the
contents of SI and DI)
Suppose, DS = 2000H , ES = 4000H
SI = 0500H , DI = 0300H
DS + SI (source) --------- [20500H] = 38H
ES + DI (destination)---- [40300H] = 45H
Then after the execution of MOVS BYTE,
The location [40300H]=38H & SI= 0501H, DI=0301H (auto
incremented)
The contents of other registers and memory locations are unchanged
35
36
I/O modes
• Standard I/O uses port addressing modes. There are two types port
addressing modes, direct and indirect.
• In direct port mode, the port number is an 8-bit immediate operand.
• For eg: OUT 05H , AL
• This will outputs content of AL to 8-bit port 05H
• In indirect port mode, port number is taken from DX.
• For eg: IN AL, DX
• If DX= 5040H, the above instruction will input the 8-bit content of
port 5040H into AL.
• On the other hand, IN AX, DX will input the 8-bit content of the
port 5040H and 5041H into AL and AH respectively.
• 8-bit and 16-bit I/O transfers must take place through AL and AX
respectively.
37
38
Relative Addressing Mode
• Instructions using this mode specify the operand as
a signed 8 bit displacement relative to PC.
• Eg; JNC START (JNC – Jump if No Carry)
• This instruction means that if carry = 0, then PC is
loaded with the current PC contents plus the 8 bit
signed value of START;
otherwise (if carry =1) the next instruction is
executed.
39
Implied Addressing Mode
• Instructions using this mode have no operand
• In implied addressing the operand is specified in the instruction
itself.
• In this mode the data is 8 bits or 16 bits long and data is the part
of instruction . Zero address instruction are designed with
implied addressing mode.
• E.g: CLC
• Clears the carry flag to zero.
40
k s
a n
T h
41