Scott Dattalo wrote: > 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. I've found that if I need to compute parity when I'm bit-banging a serial protocol, it is easiest if I just compute the parity a single bit at a time, as that bit is transmitted or received. This works quite nicely since the transmit or receive code usually already has the code to loop through all the bits, and shifts them all into the same bit position. Before the loop, I do clrf parity The loop just needs one extra instruction, xorwf parity At the end of the loop, the resultant parity is in the LSB or MSB of 'parity', depending on which way the bits get shifted. So my "solution" takes a total of 9 cycles (two more than Scott's), but only two instructions. However, my best solution that doesn't "cheat" takes 8 instructions, 8 cycles, trashes X and W, and leaves the result in the LSB of either X or W (your choice). I'll have to think about it some more to figure out how Scott shaved it down to 7 cycles. Cheers, Eric