+ All Categories
Home > Documents > 2.4 logic instructions.pdf

2.4 logic instructions.pdf

Date post: 05-Nov-2015
Category:
Upload: omar-bassam
View: 228 times
Download: 0 times
Share this document with a friend
20
 prepared by : Maher AL-Omari Logic instructions  Logic instructions AND OR XOR Complement  AND OR XOR Complement Rotate swapping  Rotate swapping affect bit Z affects bit C does not affect any 
Transcript
  • prepared by : Maher AL-Omari

    Logic instructionsLogic instructionsANDORXORComplement

    ANDORXORComplementRotateswappingRotateswapping

    affect bit Z

    affects bit C

    does not affect any

  • prepared by : Maher AL-Omari

    ANDWF f,dANDWF f,d

    Syntax: [ label ] ANDWF f,d Operands: 0 f 127 d [0,1] Operation: (W) . (f) (destination)Description: And the contents of the W register

    with register f. If d is 0, the result is stored in the W register. If d is 1, the result is stored back in register f.

    Syntax: [ label ] ANDWF f,d Operands: 0 f 127 d [0,1] Operation: (W) . (f) (destination)Description: And the contents of the W register

    with register f. If d is 0, the result is stored in the W register. If d is 1, the result is stored back in register f.

  • prepared by : Maher AL-Omari

    ANDLW kANDLW k

    Syntax: [ label ] ANDLW K Operands: 0 k 255

    Operation: (W) . k (W)Description: And the contents of the W register

    with k. the result is stored in the W register.

    Syntax: [ label ] ANDLW K Operands: 0 k 255

    Operation: (W) . k (W)Description: And the contents of the W register

    with k. the result is stored in the W register.

  • prepared by : Maher AL-Omari

    Bit maskingBit masking

    10100100W=25h

    10100101w=A5h

    D0D1D2D3D4D5D6D7

    ANDLW 3fANDLW 3f

    ( ( Z = 0Z = 0, ), )

    00 00 11 11 11 11 11 11

  • prepared by : Maher AL-Omari

    IORWF f,dIORWF f,d

    Syntax: [ label ] IORWF f,d Operands: 0 f 127 d [0,1] Operation: (W) OR (f) (destination)Description: OR the contents of the W register with register f.

    If d is 0, the result is stored in the W register. If d is 1, the result is stored back in register f.

    Syntax: [ label ] IORWF f,d Operands: 0 f 127 d [0,1] Operation: (W) OR (f) (destination)Description: OR the contents of the W register with register f.

    If d is 0, the result is stored in the W register. If d is 1, the result is stored back in register f.

  • prepared by : Maher AL-Omari

    IORLW kIORLW k

    Syntax: [ label ] IORLW k Operands: 0 k 255

    Operation: (W) OR k (W)Description: OR the contents of the W register

    with register k. The result is stored in the W register.

    Syntax: [ label ] IORLW k Operands: 0 k 255

    Operation: (W) OR k (W)Description: OR the contents of the W register

    with register k. The result is stored in the W register.

  • prepared by : Maher AL-Omari

    Logical OR-ing is used to set selected bitsLogical OR-ing is used to set selected bits

    11110111

    11000111W=E3

    D2D3

    IORLWIORLW 0C

    EFHEFH00 00 00 00 11 11 00 00

    ((Z = 0Z = 0,) ,)

  • prepared by : Maher AL-Omari

    XORWF f,dXORWF f,d

    Syntax: [ label ] XORWF f,d Operands: 0 f 127 d [0,1] Operation: (W) xOR (f) (destination)Description: XOR the contents of the W register

    with register f. If d is 0, the result is stored in the W register. If d is 1, the result is stored back in register f.

    Syntax: [ label ] XORWF f,d Operands: 0 f 127 d [0,1] Operation: (W) xOR (f) (destination)Description: XOR the contents of the W register

    with register f. If d is 0, the result is stored in the W register. If d is 1, the result is stored back in register f.

  • prepared by : Maher AL-Omari

    XORLW kXORLW k

    Syntax: [ label ] XORLW k Operands: 0 k 255

    Operation: (W) xOR k (W)Description: XOR the contents of the W register

    with register k. The result is stored in the W register.

    Syntax: [ label ] XORLW k Operands: 0 k 255

    Operation: (W) xOR k (W)Description: XOR the contents of the W register

    with register k. The result is stored in the W register.

  • prepared by : Maher AL-Omari

    Complementing certain bitsComplementing certain bits

    10100110W=65h

    10100101w=A5h

    D0D1D2D3D4D5D6D7

    XORLW C0XORLW C0

    ( ( Z = 0Z = 0, ), )

    11 11 00 00 00 00 00 00

  • prepared by : Maher AL-Omari

    Example 3:using arithmetic instructions

    addlw 1

    addlw 0xff

    xorlw 0xff

    xorlw 0xffaddlw 1

    andlw 0xf0

    iorlw 0x0f

    Increment W:

    Decrement W:

    Logic negation (1-complement):

    2-complement for W:

    Mask bits 3, 2, 1, 0:

    Set 3, 2, 1,0:

  • prepared by : Maher AL-Omari

    Two complement subtraction

    movf reg1,0xorlw 0xffaddlw 0x01Addwf reg2,0Movwf reg3

    movf reg1,0xorlw 0xffaddlw 0x01Addwf reg2,0Movwf reg3

    Reg3=reg2-reg1

  • prepared by : Maher AL-Omari

    Syntax: [ label ] COMF f,d Operands: 0 f 127

    d [0,1]

    Operation: (f) (destination) Status Affected: zDescription: The contents of register f are complemented. If d is

    0, the result is stored in W. If d is 1,the result is stored back in register f

    Syntax: [ label ] COMF f,d Operands: 0 f 127

    d [0,1]

    Operation: (f) (destination) Status Affected: zDescription: The contents of register f are complemented. If d is

    0, the result is stored in W. If d is 1,the result is stored back in register f

    COMF f,dCOMF f,d

  • prepared by : Maher AL-Omari

    Syntax: [ label ] RLF f,d Operands: 0 f 127

    d [0,1] Operation: Status Affected: cDescription: The contents of register f are rotated one bit to the

    left through the Carry flag. If d is 0, the result is placed in the W register. If d is 1, the result is placed

    back in register f

    Syntax: [ label ] RLF f,d Operands: 0 f 127

    d [0,1] Operation: Status Affected: cDescription: The contents of register f are rotated one bit to the

    left through the Carry flag. If d is 0, the result is placed in the W register. If d is 1, the result is placed

    back in register f

    RLF f,dRLF f,d

    D7 D0C

  • prepared by : Maher AL-Omari

    Given Reg2 =96 & the carry is 0what is reg2= w= after execution

    MOVLW 0X0FANDWF REG2,1RLF REG2,1RLF REG2,0ADDLW 0X07

    MOVLW 0X0FANDWF REG2,1RLF REG2,1RLF REG2,0ADDLW 0X07

    REG2=d12 , W=d31

  • prepared by : Maher AL-Omari

    Syntax: [ label ] RRF f,d Operands: 0 f 127

    d [0,1] Operation: Status Affected: cDescription: The contents of register f are rotated one bit to the

    right through the Carry flag. If d is 0, the result is placed in the W register. If d is 1, the result is placed

    back in register f

    Syntax: [ label ] RRF f,d Operands: 0 f 127

    d [0,1] Operation: Status Affected: cDescription: The contents of register f are rotated one bit to the

    right through the Carry flag. If d is 0, the result is placed in the W register. If d is 1, the result is placed

    back in register f

    RRF f,dRRF f,d

    D7 D0C

  • prepared by : Maher AL-Omari

    Example 2Example 2

    00x0C0x360X06rlf reg2,0

    00X060x360X06movwf reg2

    0NA0x360X06andlw 0x0F

    0NA0x360X36movf reg1,0

    C=0reg2Reg1=0x36

    W

  • prepared by : Maher AL-Omari

    Syntax: [ label ] SWAPF f,d Operands: 0 f 127

    d [0,1] Operation: (f) (destination),

    (f) (destination) Status Affected: --Description: The upper and lower nibbles of register f are

    exchanged. If d is 0, the result is placed in the W register. If dis 1, the result is placed in register f.

    Syntax: [ label ] SWAPF f,d Operands: 0 f 127

    d [0,1] Operation: (f) (destination),

    (f) (destination) Status Affected: --Description: The upper and lower nibbles of register f are

    exchanged. If d is 0, the result is placed in the W register. If dis 1, the result is placed in register f.

    SWAPF f,dSWAPF f,d

    0 0 1 0 1 1 0 1D7 D0

  • prepared by : Maher AL-Omari

    Logic instructionsLogic instructionsMnemonic Operation Affects andwf f, d f and W = > d ZAndlw k k and W = > W Ziorwf f, d f or W = > d Ziorlw k k or W = > W Zxorwf f, d f xor W = > d Zxorlw k k xor W = > W Zrlf f, d rotate f left through C = > d Crrf f, d rotate f right through C = > d Ccomf f, d #f = > d Zswapf f, d fL fH = > d

    Mnemonic Operation Affects andwf f, d f and W = > d ZAndlw k k and W = > W Ziorwf f, d f or W = > d Ziorlw k k or W = > W Zxorwf f, d f xor W = > d Zxorlw k k xor W = > W Zrlf f, d rotate f left through C = > d Crrf f, d rotate f right through C = > d Ccomf f, d #f = > d Zswapf f, d fL fH = > d


Recommended