lecture 4 8-bit+avr+instruction+setlec4

Upload: chusmanullah

Post on 30-May-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    1/50

    Lecture 48-bit AVR Instruction Set

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    2/50

    Status Register (SREG)

    SREG: Status Register

    C: Carry Flag

    Z: Zero Flag

    N: Negative Flag V: Twos complement overflow indicator

    S: N +V, For signed tests

    H: Half Carry Flag

    T: Transfer bit used by BLD and BSTinstructions.

    I: Global Interrupt Enable/Disable Flag

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    3/50

    Registers and Operands

    Rd: Destination (and source) register

    Rr: Source Register

    R: Result after instruction is executed

    K: Constant data K: constant address

    b: Bit in Register File or I/O Register (3-bit)

    s: Bit in the Status Register (3-bit)

    X, Y, Z: Indirect Address Register

    (X=R27:R26, Y=R29:R28 and Z=R31:R30)

    A: I/O location address

    q: Displacement for direct addressing (6-bit)

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    4/50

    The program and Data addressing modes

    RISC MC supports powerful and efficient

    addressing modes for access to the

    Program memory (Flash) and Datamemory (SRAM, Register file, I/O

    Memory, and extended I/O Memory).

    In the following figures, OP means the

    operation code part of the instruction word.

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    5/50

    Register Direct, Single Register Rd

    E.g. Inc Rd

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    6/50

    Register Direct, Two Registers Rd and Rr

    Operands are contained in register r (Rr) and d(Rd).

    The result is stored in register d (Rd).

    E.G ADD Rd, Rs

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    7/50

    I/O Direct Addressing

    Operand address is contained in 6 bits of the instructionword. N is the destination or source register address.

    E.g In Rd, PORTADDRESS ; Out PORTADDRESS,Rs

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    8/50

    Direct Data Addressing

    A 16-bit Data Address is contained in the 16 LSBs of atwo-word instruction. Rd/Rr specify the destination orsource register. E.g. LDS Rd, K;K is a 16-bit address.STS K, Rs.

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    9/50

    Data Indirect with Displacement

    Operand address is the result of the Y- or Z-register contents

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    10/50

    Data Indirect Addressing

    Operand address is the result of the X-, Y- or Z-register.

    E.g. LD Rd, X. (X is the Pointer Register)

    LD Rd, X+. X is pointer and is incremented after load.

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    11/50

    Data Indirect with Pre-decrement

    The X-, Y-, or the Z-register is decremented before theoperation. Operand address is the decrementedcontents of the X-, Y-, or the Z-register.

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    12/50

    Data Indirect with Post-increment

    The X-, Y-, or the Z-register is incremented after

    the operation. Operand address is the content of

    the X-, Y-, or the Z-register prior to incrementing

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    13/50

    Direct Program Addressing, JMP and

    CALL

    Program execution continues at the

    address immediate in the instruction word.

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    14/50

    Indirect Program Addressing, IJMP and

    ICALL

    Program execution continues at addresscontained by the Z-register (i.e., the PC isloaded with the contents of the Z-register

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    15/50

    Relative Program Addressing, RJMP and

    RCALL

    Program execution continues at addressPC+k+1. The relative address k is from -2048 to2047.

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    16/50

    ADD Add without Carry

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    17/50

    ADD Add without Carry

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    18/50

    ADD Add without carry

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    19/50

    AND Logical AND

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    20/50

    AND Logical AND

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    21/50

    AND Logical AND

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    22/50

    BREQ Branch if Equal

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    23/50

    BRGE Branch if Greater or Equal

    (Signed)

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    24/50

    BRLO Branch if Lower (Unsigned)

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    25/50

    BRNE Branch if not Equal

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    26/50

    CALL Long call to a subroutine

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    27/50

    CBR Clear Bits in Register

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    28/50

    CLR Clear Register

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    29/50

    COM Ones Complement

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    30/50

    CP - Compare

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    31/50

    DEC - Decrement

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    32/50

    IN Load an I/O Location to Register

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    33/50

    INC - Increment

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    34/50

    LD Load Indirect from Data Space to

    Register using Index X

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    35/50

    LDI Load Immediate

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    36/50

    LDS(16-bit) Load Direct from Data

    Space

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    37/50

    LSL Logical Shift Left

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    38/50

    LSR Logical Shift Right

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    39/50

    MOV Copy Register

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    40/50

    MUL Multiply Unsigned

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    41/50

    NEG Twos Complement

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    42/50

    OR Logical OR

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    43/50

    OUT Store Register to I/O Location

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    44/50

    POP Pop Register from Stack

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    45/50

    PUSH Push Register on Stack

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    46/50

    SBIS Skip if Bit in I/O Register is Set

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    47/50

    SBIC Skip if Bit in I/O Register is

    Cleared

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    48/50

    ST Store Indirect from Register to Data

    Space using Index X

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    49/50

    STS Store Direct to Data Space

  • 8/9/2019 Lecture 4 8-Bit+AVR+Instruction+SetLec4

    50/50

    SWAP Swap Nibbles