lect2-assemb1

Embed Size (px)

Citation preview

  • 8/8/2019 lect2-assemb1

    1/16

    10/23/2010CAP2211

    Lecture 2

    BASIC INSTRUCTIONS

  • 8/8/2019 lect2-assemb1

    2/16

    10/23/2010CAP2212

    MOV instruction

    Is used to transfer data :

    between registers,

    between a register & a memory location.

    Or To move a number directly into a register or

    memory location.

    Syntax

    MOV destination , source

  • 8/8/2019 lect2-assemb1

    3/16

    10/23/2010CAP2213

    Examples:

    MOV AX , WORD1

    MOV AX , BX

    MOV AH , A

  • 8/8/2019 lect2-assemb1

    4/16

    10/23/2010CAP2214

    XCHG instruction

    (Exchange) operation is used to exchange

    the contents of

    two registers, or

    a register and a memory location

    SyntaxXCHG destination , source

  • 8/8/2019 lect2-assemb1

    5/16

    10/23/2010CAP2215

    Examples:

    XCHG AH , BL

    XCHG AX , WORD1

  • 8/8/2019 lect2-assemb1

    6/16

    10/23/2010CAP2216

    Restrictions on MOV & XCHG

    SourceOperand

    GeneralRegister

    SegmentRegister

    MemoryLocation

    Constant

    GeneralRegister

    yes yes yes noSegmentRegister yes no yes no

    MemoryLocation yes yes no no

    Constant yes no yes no

    MOV Destination Operand

  • 8/8/2019 lect2-assemb1

    7/16

    10/23/2010CAP2217

    Restrictions on MOV & XCHG

    XCHG Destination Operand

    SourceOperand

    GeneralRegister

    MemoryLocation

    General

    Register yes yes

    MemoryLocation yes no

  • 8/8/2019 lect2-assemb1

    8/16

    10/23/2010CAP2218

    ADD & SUB

    Are used to add & subtract the contents of

    two registers,

    a register & memory location , or

    add ( subtract ) a number to ( from ) a register or amemory location.

    Syntax

    ADD destination , source

    SUB destination , source

  • 8/8/2019 lect2-assemb1

    9/16

    10/23/2010CAP2219

    Example

    Examples

    ADD WORD1 , AX

    SUB AX , DX

    ADD BL , 5

  • 8/8/2019 lect2-assemb1

    10/16

    10/23/2010CAP22110

    Legal combinations of operands forADD & SUB

    Memory locationGeneral RegisterSource Operand

    yesyesGeneral Register

    noyesMemory location

    yesyesConstant

    Destination operand

  • 8/8/2019 lect2-assemb1

    11/16

    10/23/2010CAP22111

    INC ( increment )&DEC ( decrement )

    INC: Is used to add 1 to the contents ofa

    Register or

    Memory location

    DEC: Is used to subtract 1 from thecontents of a

    Register or

    Memory location

  • 8/8/2019 lect2-assemb1

    12/16

    10/23/2010CAP22112

    SyntaxINC destination

    DEC destination

    Examples:

    INC WORD1

    DEC BYTE1

  • 8/8/2019 lect2-assemb1

    13/16

    10/23/2010CAP22113

    NEG

    Is used to negate the contents of the destination.

    The destination may be aregisterormemory location.

    It does this by replacing the contents by itstwos complement.

    SyntaxNEG destination

  • 8/8/2019 lect2-assemb1

    14/16

    10/23/2010CAP22114

    Translation of HLL toAssembly Language

    Statement Translation

    A = 5 A MOV AX , 5 ; put 5 in AX

    SUB AX , A ; AX. 5 AMOV A , AX ; put it in A

    There is another shorter way :

  • 8/8/2019 lect2-assemb1

    15/16

    10/23/2010CAP22115

    NEG A ; A = - A

    ADD A , 5 ; A = 5 - A

  • 8/8/2019 lect2-assemb1

    16/16

    10/23/2010CAP22116

    Translation of HLL toAssembly Language

    Statement Translation

    A = B 2 * A MOV AX , B ; AX has B

    SUB AX , A ; AX has B ASUB AX , A ; AX has B 2 * A

    MOV A , AX ; move results to B