This may seem rather obvious to some of you, but the fastest way I know to compute parity is to XORWF Parity,F inline with my serial output routine (assuming a firmware bit-bang engine). Since the data to be output is being shifted to the right in my code loop, Bit 0 of Parity contains the desired result of all N bits when all data bits have been shifted out (generates odd parity). I then shift Bit 0 of Parity out as the final bit before the stop bit. Since the XORWF is inline, it takes only 1 cycle to compute parity per bit. Ya can't do it any faster than that. Sorry, but the code is part of a commercial product - and I don't have authorization to disclose the actual serial bit-bang routine here. But jeez, you get the gist of it: the concept couldn't be simpler. (Ceeeeripes Man! It's 1 lousy instruction in your output loop! ;-) Cheers, Chuck > -----Original Message----- > From: Scott Dattalo [SMTP:sdattalo@UNIX.SRI.COM] > Sent: Friday, March 13, 1998 5:27 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: Parity Challenge > > It's been a while since there's been a challenge. And since there's > been a bunch talk about RS232 stuff, I thought it might be appropriate > if we had a really fast parity generator for those software > bit-banging > UARTs. > > So here's the challenge: > Given the variable X, write a routine that computes the odd-parity > of X. > > Here's a routine that's slow/looped: > > CLRF parity > LOOP: > CLRC > RRF X,F ;Get LSB and put it in the carry > SKPNC ;If LSB (i.e. C) is set > INCF parity,F ;then count it > MOVF X,F > SKPZ > GOTO LOOP > > The least significant bit of 'parity' contains the parity of X. > > The best I could do executes in 7 cycles and trashes X. > > Scott