COLAB_Lect1

Embed Size (px)

Citation preview

  • 8/8/2019 COLAB_Lect1

    1/20

    DrNoor Mahammad Sk

    6August2010 1DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    2/20

    Outline

    8086Architecture

    InstructionSet

    AssemblyLanguageProgramming Pro rammin Assi nments

    8086Interfacing

    InterfacingHardwaredesignsanditsprogramming

    MicrocomputerSystemDesign

    Givenspecifications

    Applications

    6Au ust2010 2DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    3/20

    8086MicroprocessorTwoparts

    BusInterfaceUnit BIU

    Hardwarefunctions

    GenerationofthememoryandI/Oaddressesforthe

    transferofdatabetweentheoutsideworldandviceversa

    ExecutionUnit(EU) ReceivestheprograminstructioncodesanddatafromBIU

    Executestheseinstructions,andstorestheresultsinthe

    . BypassingthedatabacktoBIU,datacanalsobestoredin

    amemorylocationorwrittentoanoutputdevice.

    6Au ust2010 3DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    4/20

    InternalBlockDiagramof8086Addressbus Databus

    I

    nArithmetic

    Address generation

    and bus control

    6 5 4 3 2 1

    t

    e

    r

    n

    LogicUnitFlags

    a

    l

    D

    AH AL

    BH BL

    GeneralPurposeRegistersAX

    BX

    CS

    ES

    SS

    a

    t

    a

    CH CL

    DH DL

    BP

    CX

    DX

    DS

    Instruction Pointer

    B

    u

    s

    SI

    SP

    BusInterfaceUnit(BIU)Execution

    Unit

    (EU)

    6Au ust2010 4DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    5/20

    FetchandExecution

    (IP)ontotheaddressbus,causingtheselectedbyteorwordto

    bereadintotheBIU.

    Register

    IP

    is

    incremented

    by

    1

    to

    prepare

    for

    the

    next

    instructionfetch

    , u u u .

    Thisfirstin,firstoutstorageregistersometimeslikenedtoa

    pipeline

    Assumingthequeueisinitiallyempty.TheEUimmediately

    drawsthisinstructionfromthequeueandbeginsexecution

    e sexecu ng s ns ruc on, e procee s ofetchanewinstruction.

    De endin ontheexecutionofthefirstinstruction theBIU

    mayfillthequeuewithseveralnewinstructionsbeforetheEU

    isreadytodrawitsnextinstruction6Au ust2010 5DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    6/20

    ProgrammingModelAH ALAX Accumulator

    CH CLDH DL

    CXDX

    CountData

    FlagsH FlagsL

    ControlFlags

    SP StackPointer ExtraSe mentBP

    SI

    DI

    BasePointer

    SourceIndex

    DestinationIndex

    CS CodeSegment

    DS DataSegment

    IP InstructionPointer

    6Au ust2010 6DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    7/20

    FlagRegisterBit

    Position

    Name Function

    0 CF Setonhighorderbitcarryorbarrow;clearedotherwise

    4 AF Setoncarryfromorborrow totheloworder4bitsofAL;clearedotherwise

    6 ZF Setifresult iszero;clearedotherwise

    7 SF Setequaltohighorderbitofresult(0ispositive, 1ifnegative)

    8 TF Onceset, asinglestepinterruptoccursafterthenextinstructionexecutes;TFisclearedby

    thesinglestepinterrupt

    9 IF W enset,

    mas a e interrupts

    wi

    cause

    t e

    CPU

    to

    trans er

    contro

    to

    an

    interrupt

    vector

    specifiedlocation

    10 DF Causesstringinstructionstoautodecrementtheappropriateindexregister whenset;

    clearingDFcausesautoincrement

    11 OF Setifthesignedresultcannotbeexpressedwithinthenumberofbitsinthedestination

    operand;clearedotherwise

    6Au ust2010 7DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    8/20

    SegmentedMemory8086microprocessorhas20bitaddresslines

    220 Addresslocationscanbeaccessed

    Eachmemorylocationstore1byte(8bits)ofinformationIthas16bitdatalines

    Twomemorylocationshold1wordofinformation

    Itmeansitwillhavelowerbyteandhigherbyte Alllowerbytescanbestoredinevenlocations

    CalledEVENbank

    e g er y escan es ore neven oca ons CalledODDBank

    6Au ust2010 8DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    9/20

    MemoryBanksByte 1048574

    Byte 1048575Word 524287

    EvenBank OddBank1048574 1048574

    Byte 7Word

    68

    79

    Byte 4

    Byte 5

    Read 1

    eastartingat an oddaddress

    Byte 4

    Byte 5Word 2

    0

    2

    4

    1

    3

    5

    Byte 1

    Byte 2

    Byte 3Word 1

    16 bit data word to 8086

    If a 16 bit word begins at an oddaddress, the 8086 will require

    two memory read or write cycles

    Byte 0

    6Au ust2010 9DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    10/20

    MemoryMapRAM 00000Hto3FFFFH

    ROM FF000HtoFFFFFH

    Reserved FFFFBHtoFFFFFH S stemInterru tsandresetfunction

    Dedicated FFFF0HtoFFFFAH

    OSCalls

    6Au ust2010 10DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    11/20

    SegmentRegisters1MBmemoryspaceof8086definesfour64KB

    memoryblocks

    CodeSegment Holdsprograminstructioncodes

    DataSegment

    Stores

    data

    for

    program ac egmen

    Storeinterruptandsubroutinereturnaddresses

    Extradatasegment(oftenusedforshareddata)

    stackallhavetosharethesamememory.

    6Au ust2010 11DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    12/20

    SegmentedMemoryData Segment

    FFFFFH

    EFFFFH

    E000

    DataSegment

    E0000H

    C3FEFHCodeSegment

    o e egmen

    B3FF0H

    StackSegment

    6D26FHStack

    Segment 6288FH

    5D27

    ExtraSegment

    5 270 Segment

    52B90H

    00000H

    6Au ust2010 12DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    13/20

    DrNoor Mahamamd Sk

    6August2010 13DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    14/20

    DataTransferInstructionsMOV Destination, Source ExampleMOV Register, Register MOV AX,BX; (AX BX)

    MOV AH,BL (AH BL)

    MOV Memory, Register MOV MEMWDS,BX ;[1000H]BL;[1001H]BH

    MOV

    MEMBDS,BL

    ;[1002H]BL

    MOV Register, Memory MOV AX,MEMWDS ;AL [1000H];AH [1001H]MOV AL,MEMBDS ;AL [1002H]

    MOV Memory, ImmediateData MOV MEMWDS,1234H ;[1000H] 34H;[1001H]12HMOV MEMBDS,56H ;[1002H] 56H

    MOV Register, ImmediateDataMOV BL,18H ;BL 18H

    MOV CX,5678H ;CL 78H, CH 56H

    MOV AX/AL, Memory MOV AL,28H ;AL 28HMOV AX,5678H ;AL 78H, AH 56H

    MOV Memory, AX/AL MOV MEMWDS,AX ;[1000H]AL;[1001H]AHMOV MEMBDS AL 1002H AL

    MOV SegRegister, Memory16MOV ES,MEMWDS ;ES [1001H:1000H]

    MOV SegRegister , Register16MOV DS, AX ;DS AX

    emory16, eg eg s er ,

    MOV Register16

    , SegRegister MOV DX,ES ;DX ES

    6Au ust2010 14DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    15/20

    DataTransferInstructionsXCHG Operand1 Operand2 ExampleXCHG Register, Memory XCHGBX, [SI] ;BL [SI]; BH [SI+1]

    XCHG AX,BX ;AX BX,XCHG AL,BH ;AL BH

    XCHG Memory Register XCHG[SI],DX ;[SI] DL; [SI+1] DH

    IN Accumulator, Port IN AL, 26H ;AL port26HIN AX, 26H ;AL port26H; AH port27H

    OUT Port Accumulator OUT 26H, AL ;port26H ALOUT 26H, AX ;port26H AL;port27H AH

    LEA Destination Source LEA BX,MEMBDS ;BL 00H;BH 10H`;Effectiveaddressofthesourceoperandistransferredtothe

    destinationoperand

    XLAT NoOperands AL [BX+AL] ; ReplacethebyteinALwithabytefromthe256bytetablebeginningat[BX]; UseALasanoffsetintothis

    table

    LAHF NoO erands AH Fla s ;Co thelower orderfla b teintoAH

    SAHF NoOperands FlagsL AH ;CopyAHintotheloworderflagbyte

    6Au ust2010 15DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    16/20

    LogicalInstructionsOpcode Destination, Source ExampleNOT Register NOT BX ; BX ~BX

    NOT [SI] ;[SI] ~[SI]

    AND Destination SourceOR Destination Source

    XOR Destination Source

    TEST Destination Source TESTCX,DX ;Performs abitbybitANDofthesourceanddestinationbyteorwordoperands;

    TheoperandsremainsunchangedAllflagsgetupdatedexceptAF

    Usage:

    AND Register Register AND CX,DX

    AND Memory Register AND [SI},AX

    AND Register Memory AND AX, [SI]

    AND BX,8000H

    AND Memory Immediate Data AND [SI], FF00H

    6Au ust2010 16DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    17/20

    ShiftandRotateInstructionsOpcode Destination, Count Example

    SHL Register 1 Logical LeftShiftby1

    SHL Register Immediate Logical LeftShiftby thevalueofImmediateSHL Memory Immediate Logical LeftShiftby thevalueofImmediate

    SHL Register CL Logical LeftShiftby thecontentofCLregister

    SHL Memory CL Logical LeftShiftby thecontentofCLregister

    SAL Destination, Count Arithmetic LeftShift leavingSignBit

    SAR Destination, Count Arithmetic RightShift leavingSignBit

    SHR Destination, Count LogicalRightShift

    ,

    RCR Destination, Count Rotatethrough CarryRight

    ROL Destination, Count RotateLeft

    ROR Destination, Count RotateRight

    6Au ust2010 17DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    18/20

    ShiftandRotateInstructionsDATA

    Bit0Bit7/15

    CF 0 LogicalLeftShift SHL

    Bit0Bit7/15Lo icalRi htShift SHR

    DATA CF ArithmeticRightShift

    SF DATACFSAL

    0

    6Au ust2010 18DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    19/20

    RotateInstructionsCF DATA

    RCL

    RotateThroughCarryLeft

    RCR

    CF DATAROLRotateLeft

    CFDATARORRotateRight

    6Au ust2010 19DrNoorMahammadSk

  • 8/8/2019 COLAB_Lect1

    20/20

    ArithmeticInstructionsOpcode Destination, Source Expression

    ADD Dest Src Dest =Dest +Src

    =

    SUB Dest Src Dest =Dest SrcSBB Dest Src Dest =Dest Src C

    CMP Dest Src Dest Src (andsetflags);OperandsRemainedUnchanged

    INC Dest Dest =Dest +1DEC Dest Dest =Dest 1

    NEG Dest Dest = Dest ;(2scomplement ofDest)

    MUL Src [DX][AX] [AX] *[Dest]

    [AX] [AL]*[Dest]

    IMUL Src [DX][AX] [AX] *[Dest]

    [AX] [AL]*[Dest]

    Signed Multiplication

    6Au ust2010 20DrNoorMahammadSk