On Sunday, March 19, 2000 Scott Dattalo wrote: > For a single byte there is a 14-cycle solution. But since it looks like your > having fun, I wouldn't want to spoil anything. :) I have more fun to learn from PICLIST members :) > BTW, John Payson posted the original solution (for reversing 7 bits). Dmitry > optimized it slightly (again for 7 bits). John's trick is applicable here as > well. > Hint, for the general case, it takes 4 cycles to swap 2 bits. However, it only > takes 2 cycles for the first two bits. > Scott AFAIR, Dmitry used swap to place two bits in place, and then xor'd to swap individual pairs of bits. How about this: ;In = abcdefgh ;Out = hgfedcba rlf In, w ;carry = a swapf In, f ;In = efghabcd rlf In, w ;w = fghabcda (-g---c-a), carry = e andlw 0xEF skpnc iorlw 0x10 ;w = fghebcda (-g-e-c-a) btfsc In, 6 xorlw 0xA0 btfsc In, 4 xorlw 0xA0 ;w = hgfebcda (hgfe-c-a) btfsc In, 2 xorlw 0x0A btfsc In, 0 xorlw 0x0A ;w = hgfedcba ;14 instructions so far ;1 more to copy w to Out movwf Out >From the practical point of view, it's better to have ability to reassign pins in any order. I use pins masks always - it's easier to route PCB then. Nikolai