P9 8086 Addressing Modes

Embed Size (px)

DESCRIPTION

Addressing modes.

Citation preview

  • 8/5/2013

    1

    Dr. M. Tariq Dr. M. Tariq Dr. M. Tariq Dr. M. Tariq BandayBandayBandayBandayPG Department of Electronics & Instrumentation

    Technology, UoK, Srinagar

    P9

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    An Assembly language instruction can be divided into two parts: Operation code (opcode) one- to five-letter mnemonic mnemonic mnemonic mnemonic , and

    Operands (None, One or More Operands)

    MENMONIC OPRANDSE.g.

    MOV AX, BX

    MnemonicMnemonicMnemonicMnemonic

    SourceSourceSourceSourceSourceSourceSourceSourceOperandOperandOperandOperand

    DestinationDestinationDestinationDestinationDestinationDestinationDestinationDestinationOperandOperandOperandOperand

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    The move (MOV) instruction is used totransfer a byte or a word of data from asource operand to a destination operand.

    Examples: MOV AX, BX

    MOV AX, [BX]

    MOV BX, [2000]

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Note that the MOV instruction cannot transfer data directly between external memory.

    MTBStamp

  • 8/5/2013

    2

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    An Addressing mode is defined as amethod of specifying the effectiveaddress of the operands in memory.

    The addressing mode increases theflexibility of the programminglanguages.

    It is used in implementing the constructsand data structures of the powerful highlevel programming language.

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Implicit Addressing

    Immediate Addressing

    Register Addressing

    Memory Addressing Modes Direct Addressing

    Indirect Addressing

    Register Indirect Addressing

    Based Addressing

    Indexed Addressing

    Based Indexed Addressing

    Inter Segment Direct Addressing

    Inter Segment Indirect Addressing

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    In this mode the instruction assumes that data is in some pre defined register which varies from one instruction to other. Such instructions are also called zero address instructions. E.g. CMC

    STD

    CLC, etc.

    OPCODEOPCODEOPCODEOPCODE

    Instruction

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    In this mode data (Operand) is part of theinstruction. It does not involve computationof address.

    e.g.

    MOV AX, 100h AX100h

    MOV AL, 15h AL15h

    OPCODEOPCODEOPCODEOPCODE DATADATADATADATA

    Instruction

    MTBStamp

  • 8/5/2013

    3

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Status of CPU before Execution of InstructionMOV AL, 15H

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    After Execution of Instruction MOV AL, 15H

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    In this mode, operands on which instructionsoperate are stored in some internal registerof the microprocessor. Operand may be insome 16 bit or 8 bit register.

    16 bit register may be any one from: AX, BX, CX,DX, SP, BP, SI, DI, CS, DS, SS or ES

    8 bit register may be AL, AH, BL, BH, CL, CH, DL orDH

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    OPCODEOPCODEOPCODEOPCODE RegisterRegisterRegisterRegister

    Instruction

    DataDataDataData

    Register

    E.g.

    MOV AX, BX AXBXMOV AL, CL ALCL

    MTBStamp

  • 8/5/2013

    4

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Before execution of instruction MOV AX, BX

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    After execution of instruction MOV AX, BX

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Direct Addressing Modes

    Indirect Addressing Modes

    Register Indirect Addressing

    Based Addressing

    Indexed Addressing

    Based Indexed Addressing

    Inter Segment Direct

    Inter Segment Indirect

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    To reference an Operand in memory,8086/8088 calculates Physical Address (PA)of the Operand and then initiates a read orwrite operation to this location.

    Physical Address (PA) 20 bit address of memory location

    Segment Base Address (SBA) 16 bit address of the segment in use as specified byany one of Segment Registers.

    Effective Address (EA) 16 bit logical address specifying offset fromsegment base address

  • 8/5/2013

    5

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Registers used in computation of Physical address of memory

    One of the Segment Registers (CS, SS, DS or ES) and one or more of the following:

    One of the Base Registers (BX or BP) BP can not used independently in the addressing mode

    One of the Index Registers (SI or DI), and

    8 Bit or 16 Bit displacement

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Segment, Base, index and displacement is combined as following:

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    In this mode data is in memory and theaddress of the data is part of the Instruction.The address is hard coded with theinstruction itself.

    E.g. MOV AX, [1234H]

    OPCODEOPCODEOPCODEOPCODE EAEAEAEA

    Instruction

    DataDataDataData

    Memory

  • 8/5/2013

    6

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Before execution of instruction MOV CX, [1234H]

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    After execution of instruction MOV CX, [1234H]

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Assuming DS = 0200H, calculate the PA of memory locations used as source/destination in the following instructions:

    MOV CX, [1234H]

    MOV [2000H], CL

    MOV AL, [1340H]

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    In this addressing mode the effective addressof the Operand is in register. The data onwhich the instruction operates is pointed toby register (BX, SI, DI) which is part of theinstruction.

    OPCODEOPCODEOPCODEOPCODE RegisterRegisterRegisterRegister

    Instruction

    EAEAEAEA

    Register

    DATADATADATADATA

    Memory

    e.g.MOV AX, [BX]

    MTBStamp

  • 8/5/2013

    7

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Computation of Physical Address

    PA=Segment Base : Register

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Before execution of Instruction MOV AX, [SI]PA = 0200H X 10H + 1234H = 03234H

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    After execution of Instruction MOV AX, [SI]PA = 0200H X 10H + 1234H = 03234H

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    In this the EA of the Operand is calculated byadding contents of one of Base Registers (BP orBX) and 8 or 16 bit offset. This is a RegisterRelative addressing mode that uses one of theBase Registers.

    E.g. MOV [BX]+1234H, AL

    MOV [BX + 20h], AL

    MOV AX, [BP +2000H]

    MTBStamp

  • 8/5/2013

    8

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Assuming DS = 0200H, SS = 0400h, BX = 1000H and BP = 2000H Calculate the PA of memory locations used as source/destination in the following instructions:

    MOV [BX]+1234H, AL

    MOV [BX + 20h], AL

    MOV AX, [BP +2000H]

    MOV CX,[BX+1000H]

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Address Calculation

    OPCODEOPCODEOPCODEOPCODE RegisterRegisterRegisterRegister

    Instruction

    AddressAddressAddressAddress

    Base Register

    EAEAEAEA

    Memory

    DisplacementDisplacementDisplacementDisplacement

    ++++

    DATADATADATADATA

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Address Calculation

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Before execution of instruction MOV [BX] +1234H, AL

    PA = 0200H X 10H + 1000H +1234H = 04234H

    MTBStamp

  • 8/5/2013

    9

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    After execution of instruction MOV [BX] +1234H, AL

    PA = 0200H x 10H + 1000H +1234H = 04234H

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    In this the EA of the Operand is calculated byadding contents of one of Index Registers (SI orDI) and 8 or 16 bit offset. This is a RegisterRelative addressing mode that uses one of theIndex Registers.

    E.g. MOV [SI]+1234H, AL

    MOV [DI+ 20h], AL

    MOV AX, [SI+2000H]

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Address Calculation

    OPCODEOPCODEOPCODEOPCODE RegisterRegisterRegisterRegister

    Instruction

    AddressAddressAddressAddress

    Index Register

    EAEAEAEA

    Memory

    DisplacementDisplacementDisplacementDisplacement

    ++++

    DATADATADATADATA

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Address Calculation

    MTBStamp

  • 8/5/2013

    10

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Before execution of instruction MOV AL, [SI] +1234H

    PA = 0200H X 10H + 2000H +1234H = 05234H

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    After execution of instruction MOV AL, [SI] +1234H

    PA = 0200H X 10H + 2000H +1234H = 05234H

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    In this the EA of the Operand is calculated byadding contents of one of Base registers (BX orBP), one of Index Registers (SI or DI) and 8 or 16bit offset. This is a Register Relative addressingmode that uses one of the Index Registers.

    E.g. MOV [BX + SI]+1234H, AL

    MOV [DI+ 20h] [SI + 50H], AL

    MOV AX, [BX+SI+2000H]

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Assuming DS = 0200H, ES = 0400h, SI= 1000H and DI= 2000H Calculate the PA of memory locations used as source/destination in the following instructions:

    MOV [SI]+1234H, AL

    MOV [SI+ 20h], AL

    MOV AX, [DI+2000H]

    MOV CX, [DI+1000H]

    MTBStamp

  • 8/5/2013

    11

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Address Calculation

    OPCODEOPCODEOPCODEOPCODE RegisterRegisterRegisterRegister

    Instruction

    AddressAddressAddressAddress

    Index Register

    EAEAEAEA

    Memory

    DisplacementDisplacementDisplacementDisplacement

    ++++

    DATADATADATADATA

    RegisterRegisterRegisterRegister

    AddressAddressAddressAddress

    Base Register

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Address Calculation

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Before execution of instruction MOV AH, [BX][SI] + 1234H

    PA = 0200H X 10H + 1000H +2000H +1234H = 05234H

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    After execution of instruction MOV AH, [BX][SI] + 1234H

    PA = 0200H X 10H + 1000H +2000H +1234H = 05234H

    MTBStamp

  • 8/5/2013

    12

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Assuming DS = 0200H, ES = 0400h, SI= 1000H, BX=2000H, BP =1230H and DI= 2000H Calculate the PA of memory locations used as source/destination in the following instructions:

    MOV [BX]+[SI] +1234H, AL

    MOV [BX][SI], AL

    MOV AX, [BP+ DI + 2000H]

    MOV CX, [BX][SI]+1234H

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Inter Segment Direct CALL 0050H

    Inter Segment Indirect MOV BX, 0050H

    CALL BX

    Intra Segment Direct CALL 2000H:0050H

    Intra Segment Indirect MOV BX, 2000H

    MOV DI, 0050H

    CALL BX:DI

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    MTBStamp

  • 8/5/2013

    13

    Dr. M. Tariq Bandayhttp://banday.info

    w

    w

    w

    .

    b

    a

    n

    d

    a

    y

    .

    i

    n

    f

    o

    www.banday.info

    www.banday.info

    Thank you

    Any Questions?

    MTBStamp