On Wed, 29 Oct 1997 10:50:06 -0500, you wrote: >There hasn't been a "programming challenge" lately. Here's a problem I'm >looking at: I have a 7 bit ASCII character which was transmitted >serially LSB first, but received MSB first. Thus, I need to reverse the >order of the bits (I can't change the receiver, since other parts of the >data are transmitted MSB first). For example, 0011010 should come out as >0101100. The routine should be a subroutine which gets the input value >in W and returns the result in W. It is OK to assume the high bit of W >will be 0, and the high bit of the result must be 0 (the routine works >only on the low 7 bits) >Each ROM location used : 8 points >Each RAM location used : 30 points >Each instruction cycle (to convert once): 1 point >Uses less than 25 instruction cycles: -40 points > Compact version : 9 rom, 2 ram, 40 cycles - 172 points movwf temp movlw 2 ; end marker movwf temp2 loop rrf temp rlf temp2 skpc goto loop ; loop until bit falls out end movf temp2,w return Fast & low RAM version : 17 rom, 1 ram, 18 cycles - 144 points movwf temp clrw btfsc temp,0 iorlw 040 btfsc temp,1 iorlw 020 btfsc temp,2 iorlw 010 btfsc temp,3 iorlw 008 btfsc temp,4 iorlw 004 btfsc temp,5 iorlw 002 btfsc temp,6 iorlw 001 return