In SX Microcontrollers, SX/B Compiler and SX-Key Tool, peterverkaik wrote: The even parity calculation is done by this small routine. Remember, odd parity is inverted even parity. For 7databits, bit7 is cleared before entering this code. (a 0 bit has no effect) ; calculate even parity for w ; result in temp.0 ;--------------------------------------------------------------------------------- even_parity mov temp,w ;calculation code by John Payson, as found on sxlist.com ;This routine will leave the parity of temp in temp.0 ;while blenderizing most of the rest of temp mov w,<>temp ; temp = abcdefgh xor temp,w mov w,>>temp xor temp,w ; at this point, the parity for half the bits ; (a, b, e, and f) is in bit 2 of temp, and the ; parity for the other half (bits c, d, g, and h) ; is in bit 0 of temp. snb temp.2 ; if the parity of (a,b,e,f) is 0, ; then the parity of (a,b,c,d,e,f,g,h) ; is equal to the parity of (c,d,g,h)... ; which is already in bit 0, so skip ahead. inc temp ; otherwise, the parity of (a,b,e,f) is 1, ; so the parity of (a,b,c,d,e,f,g,h) is ; NOT equal to the parity of (c,d,g,h). ; invert bit 0. ; at this point, bit 0 contains the parity of ; (a,b,c,d,e,f,g,h). retp regards peter ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=110792#m111054 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)