thanks scott, i made the change and am reposting, your message, i did a reply and forgot to see who it was being sent to, you must have your reply to set in the mail, i leave mine blank. here is an idea (not tested) 12 bytes of code no looping, and leaves x alone. michael swapf x,w xorwf x,w ; xor nibbles, now we have only 4 bits to test andlw 0F0h ; clear lower nibble for counter movwf parity btfsc parity,4 ; test bits now incf parity,f btfsc parity,5 incf parity,f btfsc parity,6 incf parity,f btfsc parity,7 incf parity,f btfsc parity,0 ; use this to test for parity -----Original Message----- From: Scott Dattalo To: PICLIST@MITVMA.MIT.EDU Date: Friday, March 13, 1998 7:19 PM 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 >