Hi Bob and guys. John Payson would be offered this. movfw DATAIN ;abcd efgh > abcd hgfe btfsc DATAIN,0 ;exchange e and h xorlw 0x09 btfsc DATAIN,3 xorlw 0x09 btfsc DATAIN,1 ;exchange f anf g xorlw 0x06 btfsc DATAIN,2 xorlw 0x06 1 clock less, result in W as well. WBR Dmitry. Bob Ammerman wrote: > > a simple technique, perhaps not the best > > movf DATAIN,W ; Get the data > andlw 0xF0 ; Keep 4 high bits > > btfsc DATAIN,0 ; Low bit set? > iorlw 1 << 3 ; Put in new place > > btfsc DATAIN,1 > iorlw 1 << 2 > > btfsc DATAIN,2 > iorlw 1 << 1 > > btfsc DATAIN,3 > iorlw 1 << 0 > > result is left in W > > Bob Ammerman > RAm Systems > > ----- Original Message ----- > From: "Pic Dude" > To: > Sent: Friday, March 08, 2002 7:29 PM > Subject: Bit operation quiz... > > Anyone up for a pop quiz?... > > I have all Port C outputs going to 8 LED's. To save PCB space, I can > re-route > the 4 lowest lines to the LED's, but the last 4 bits get reversed. What's > the fastest > way, in code, to reverse just those 4 lowest bits, and leave the 4 highest > bits > untouched? Fastest = smallest # of steps. > > Assume input = ABCDEFGH, then output should be ABCDHGFE. > > So far I've come up with this (untested), but it's seems like a very > "sledgehammer" way to do it. There's gotta be something slicker. I > remember learning about the XOR swap trick many years ago, and > thought it was the coolest thing ever (at the time). Any thing like > that exist for doing this partial reverse? > > movf DATAIN,TEMP > rrf TEMP,F > movf TEMP,W > andlw H'02' > movwf DATAOUT ; Bit 1 done > rrf TEMP,F > rrf TEMP,W > andlw H'01' > andwf DATAOUT,F ; Bit 0 done > movf DATAIN,TEMP > rlf TEMP,F > movf TEMP,W > andlw H'04' > andwf DATAOUT,F ; Bit 2 done > rlf TEMP,F > rlf TEMP,W > andlw H'08' > andwf DATAOUT,F ; Bit 3 done > movf DATAIN,W > andlw H'F0' ; Strip out low nibble > andwf DATAOUT,F ; Merge with result > > Cheers, > -Neil. > > -- > http://www.piclist.com hint: PICList Posts must start with ONE topic: > [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads > > -- > http://www.piclist.com hint: PICList Posts must start with ONE topic: > [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics