simple instruction got me stumped

Discussion in 'Programmer's Corner' started by Man_in_UK, Sep 22, 2008.

  1. Man_in_UK

    Thread Starter Senior Member

    May 13, 2008
    132
    0
    I'm trying to expand my programming limits and I'm stuck on this ....

    XORLW

    I do know its an exclusive OR with a number 5 & the w reg, but what does it actually mean ?



    The code I am trying to figure out is .......
    movf counter,w
    xorlw 5
    btfss ststus,z
    goto delay
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,140
    1,790
    It is a way of comparing for equality. The only value in W that can produce a result of zero when Exclusive ORed with 5 is... well 5! Any other value of W when XORed with 5 will produce a non zero result.
     
  3. Man_in_UK

    Thread Starter Senior Member

    May 13, 2008
    132
    0
    That makes sense, sounds simple enough. Can I ask another ?



    From the example how does the 0 result make the status,z bit be not set ?


    What is the math to xorlw,is it a simple subtract ?
     
  4. Papabravo

    Expert

    Feb 24, 2006
    10,140
    1,790
    If the result of the XORLW is zero then the z bit of the status register will be a one. You can use btfss or btfsc to skip the next instruction if the z bit is equal to zero(set) or note equal to zer(clear).

    No it is one of the sixteen possible boolean functions of two variables. There is no concept of borrow in the exclusvive OR function. The resemblance of the truth tables for individual bits ignores the effects of borrow.

    Code ( (Unknown Language)):
    1.  
    2. 0  ^  0 = 0
    3. 0  ^  1 = 1
    4. 1  ^  0 = 1
    5. 1  ^  1 = 0
    6.  
     
    Last edited: Sep 23, 2008
  5. Man_in_UK

    Thread Starter Senior Member

    May 13, 2008
    132
    0
    Thank you.
    I was following you OK until I read the table. It shows 1xor1 = 1 & then 1xor1 =0.

    How can the same sum have two answers ?
     
  6. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    There is a typo in the third line down of that table, it should read :
    1 ^ 0 = 1
     
Loading...