TNX, Andy ! Ivan Cenov okto7@botev.ttm.bg -----Original Message----- From: Andrew Warren To: PICLIST@MITVMA.MIT.EDU Date: 01 툎 1998 ‹. 11:08 Subject: Re: What is SUM_XNOR7 ? Ivan Cenov wrote: > I dont know what exactly means "SUM_XNOR7". in calculating checksum > of code-protected devices. Microchip gives two-sentence > explanation, I tried the example but my answer does not match > their's. > > Please send me algorithm of that. Ivan: Your example doesn't match theirs because theirs is wrong (at least, it is in my 1996 edition of the programming spec). "SUM_XNOR7[a:b]" means: 1. Initialize SUM to 0. 2. Point at address "a". 3. Take the upper 7 bits of the 14-bit word to which you're pointing, and exclusive-OR it with SUM. 4. Invert your 7-bit result (i.e., change "1" bits to 0's, and vice-versa), then store it back in SUM. 5. Repeat for the lower 7 bits of the word. 6. Point at the next address. If you're not pointing at address "b+1", go back to Step 3. Using the example in Microchip's documentation: SUM_XNOR7[0:1], where address 0 contains 0x0123, and address 1 contains 0x0456: Step: SUM: Notes: ----- ---- ------ 1 0x00 2 '' 3 0x02 upper 7 bits of 0x123 = 0000010, or 0x02. 4 0x7D ~0x02 = 0x7D. 5 0x21 lower 7 bits of 0x123 = 0100011, or 0x23. 0x7D XOR 0x23 = 0x5E. ~0x5E = 0x21. 6 '' 3 0x29 upper 7 bits of 0x456 = 0001000, or 0x08. 0x21 XOR 0x08 = 0x29. 4 0x56 ~0x29 = 0x56. 5 0x7F lower 7 bits of 0x456 = 1010110, or 0x56. 0x56 XOR 0x56 = 0x00. ~0x00 = 0x7F The correct result is 0x7F; Microchip's documentation incorrectly shows it as 0x1F. -Andy === Andrew Warren - fastfwd@ix.netcom.com === Fast Forward Engineering - Vista, California === http://www.geocities.com/SiliconValley/2499 (personal) === http://www.netcom.com/~fastfwd (business)