8086 Addressing Modes

    The 8086 has 12 basic addressing modes(AM) and can be classified into 5 groups

  1. Addressing modes for accessing immediate & register data
  2. Addressing modes for accessing data in memory
  3. Addressing modes for accessing I/O ports
  4. Relative Addressing modes
  5. Implied Addressing modes

I Addressing modes for accessing Immediate & Register data

1.Register AM
    In this mode the source operand,destination operand or both are to be contained in the 8086 register.
eg:- MOV DX,CX
       MOV CL,DL

2.Immediate AM
    In this mode a 8 or 16 bit data can be specified as part of the instruction
eg:- MOV CL,03H
       MOV DX,0502H

II Addressing modes for data in memory (Memory mode)

3.Direct AM
    In this mode the 16 bit effective address (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.
    The BIU shifts the [DS] 4 times to left & adds the EA to generate the 20 bit physical address.
eg:- MOV CX,START
       MOV START,BL
START can be defined as an address by using the assembler DB(Define Byte) or DW(Define Word) pseudoinstructions.
    Suppose if START=0040(16) &
                          [DS]=3050(16)
    then 

3 0 5 0   Shift Left
  0 0 4 0 (EA)
3 0 5 4 0 20 bit physical address

 4.Register Indirect AM
    In this mode the EA is specified in either a pointer register or an index register.The pointer register can be either base register(BX) or base pointer(BP) and Index register can either be Source index(SI) or Destination index(DI) register
eg:- MOV [DI],BX
    The instruction moves the 16 bit content of BX into a memory location offset by the value of EA (EA is specified in DI) from the current contents in DS.
If [DS]=5004(16)
   [DI]=0020(16)  and
   [BX]=2456(16)
then 

5 0 0 4   Shift Left
  0 0 2 0 (EA)
5 0 0 6 0 20 bit physical address

     the contents of BX (2456) is moved into memory locations 50060(16) & 50061(16)

5.Based AM
    In this mode EA is obtained by adding a displacement (signed 8 bit or unsigned 16 bit) value to the contents of BX or BP.The segment registers used are DS & SS.

When Memory is accessed,the 20 bit physical address is computed from BX and DS.On the other hand,when the stack is accessed,the 20 bit physical address is computed from BP and SS.

eg:- MOV AL,START[BX] or MOV AL,[BX+START]

Where START=02H(8 bit displacement),BX=2000H

Now the 20 bit Physical address is computed from DS and EA

If [DS]=5004(16),then 

 
2000H BX
02H Displacement
2002H EA
 
5 0 0 4    
  2 0 0 2 EA
5 2 0 4 0 20 bit Physical Address

 Here the source operand is in based Addressing Mode.EA is obtained by adding the value of START and [BX].The 20 bit physical address is produced from DS and EA.The 8 bit content of this memory location is moved to AL register.

Therefore the contents of the memory location 52042 is moved in to AL register.

6.Indexed AM

In this mode,the EA is calculated by adding the unsigned 16 bit or signed extended 8 bit displacement and the contents of SI or DI.

eg:- MOV BH,START[SI]

moves the contents of the 20 bit address computed from the displacement START,SI and DS into BH register.The 8 bit displacement is provided by the programmer using the assembler pseudoindtruction such as EQU.For 16 bit displacement,the EU adds this to SI to determine EA.On the other hand,for 8 bit displacement the EU sign extends it to 16 bits and then adds to SI for determining EA.

7.Based Indexed AM

In this mode,the EA is computed by adding a base register(BX or BP),an index register(SI or DI),and a displacement(unsigned 16 bit or sign extended 8 bit)

eg:- MOV ALPHA[SI][BX],CL

If [BX]=0200H,[SI]=1000H,ALPHA=08H and [DS]=3000H 

 
0200H [BX]
1000H [SI]
08H Displacement
1208H EA
 
3 0 0 0    
  1 2 0 8 EA
3 1 2 0 8 20 bit Physical address

 Based Indexed AM provides a convinient way for a subroutine to address an array allocated on a stack.

8.String AM

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 to the first byte or word of the destination operand.

The segment register for the source is DS and may be overridden.The segment register for the destination must be ES and cannot be overridden.

The contents af SI and DI are automatically incremented by clearing DF (Direction Flag) to 0 by CLD instruction or automatically decremented by setting DF to 1 by STD instruction.

III Addressing Modes for accessing I/O ports

9.Direct AM

Here the port number is a 8 bit immediate operand.This allows fixed access to ports numbered 0 to 255.

eg:- OUT 05H,AL

outputs [AL] to 8 bit port 05H

10.Indirect AM

The port number is taken from DX allowing 64K 8 bit ports or 32K 16 bit ports.

eg:- IN AX,DX

If [DX]=5040,Inputs the 8 bit content of port 5040 into AL and 5041 into AH.

IV Relative Addressing Mode

11.

In this mode,the operand is specified as a signed 8 bit displacement,relative to PC(Program Counter).

eg:- JNC START

then,if carry=0,PC is loaded with current PC contents plus the 8 bit signed value of START,otherwise the next instruction is executed.

V Implied Addressing Mode

12.

Instructions using this mode have no operands.

eg:- CLC

this clears the carry flag to zero.

8086 Assembly Language Programs

Computer Organization - Introduction


© Copyrights Madhu Sudan Rao G.K  

[CodeEverywhere]