I wrote: > CASE: > > XORLW 7 > BZ W_CONTAINED_7 > > XORLW 51^7 > BZ W_CONTAINED_51 > > XORLW 12^51 > BZ W_CONTAINED_12 > and GREG OWEN replied: > What does the ^ do in your program. I looked up the ^ symbol > and it is a bitwise XOR. Why do you have this on your examples, > except the 7 one? The 51^7 and 12^51 are even more confusing. Greg: If you carefully step through the code, you'll see what's happening. First, a basic rule: If you XOR a number with itself, the result is always zero... So the first two lines of the program, XORLW 7 BZ W_CONTAINED_7 will branch to "W_CONTAINED_7" if W contained 7 before the "XORLW". Following so far? Ok... The "XORLW" instruction stores the result of the XOR back in the W-register. This means that the "XORLW 7" instruction will modify the W-register, so if W DIDN'T contain 7 (so the branch to "W_CONTAINED_7" WASN'T taken), the W-register will no longer contain its original value by the time the PIC executes the second XORLW. Therefore, the third line of the program (which tests for W = 51), can't simply say XORLW 51 because even if W DID contain 51 on entry to "CASE", it won't contain 51 by the time it gets to the third line of the program. What it WILL contain, if it was equal to 51 on entry to "CASE", is 51 XORed with 7. So... The third line of the program has to compare W to 51^7; if it's equal to THAT number, it means that W was equal to 51 at "CASE", so we branch to "W_CONTAINED_51". Now let's deal with the third possibility, W = 12. If W contained 12 at "CASE", the first XORLW will set W equal to 12^7 and the first branch won't be taken. The second XORLW will further modify W, setting it to (12^7)^(51^7), and the second branch won't be taken, either. Two more basic rules: A ^ 0 = A "xor" is associative and commutative... That is, (a^b)^c = a^(b^c), and b^c = c^b. Where were we? Oh, yeah... If W contained 12 at "CASE", it'll hold (12^7)^(51^7) by the time we get to the third XORLW. Using the associative and commutative laws, we see that: W = (12^7)^(51^7) = ((12^51)^(7^7) We know that 7^7 = 0, so W = (12^51)^0. Since A^0 = A, W = 12^51. So... If W contained 12 at "CASE", it'll contain 12^51 at the third XORLW. Therefore, we test for THAT number in the third XORLW, and if the result is zero, we branch to "W_CONTAINED_12". Does it make sense now? -Andy === Andrew Warren - fastfwd@ix.netcom.com === Fast Forward Engineering - Vista, California === http://www.geocities.com/SiliconValley/2499