Searching \ for '[PIC]: Code snippet wanted .... or ... bit swap ch' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'Code snippet wanted .... or ... bit swap ch'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Code snippet wanted .... or ... bit swap ch'
2001\02\06@181309 by Drew Vassallo

picon face
Having little free time to actually optimize my code to its fullest
potential, I'm frequently forced to take the brute force approach to many
problems.  Here's one:

I have 2 chips installed side by side that I would like to connect directly
parallel to each other's ports (8 bits each) rather than crossing the wires,
but the PORTB pins on my PIC are reversed from the matching port on the
other IC.  (RB0 lines up with IC7, etc.)

Here's my brute force bit-swapping code to reverse the output:

;------ Call into this routine with the output value in W.
;------ It will be swapped and returned in W.
;------ Example:  Input=0xA7, Output=0xE5
Bit_Swap
               movwf   InputReg
               movlw   0x08
               movwf   BCount
BS_Loop
               rrf     InputReg, f
               rlf     OutputReg, f
               decfsz  BCount, f
               goto    BS_Loop
               movf    OutputReg, w
               return

45 cycles is pretty lame.  Any ideas?

--Andrew
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\02\06@182322 by Drew Vassallo

picon face
Never mind my challenge, I should have known Dmitry had it covered:

;       Input X  = abcdefgh , Output X = hgfedcba
;       Written by Dmitry A. Kiryashov 2000
;       12 clocks/words

reverse8bit:

       swapf   X,W     ;efghabcd
       xorwf   X,W     ;efghabcd
                       ;abcdefgh

       andlw   0x66    ;.fg..bc.
                       ;.bc..fg.

       xorwf   X,F     ;afgdebch
;
       rrf     X,W
       rrf     X,F     ;hafgdebc
;
       andlw   0x55    ;.a.g.e.c
       addwf   X,F     ;h.f.d.b.
                       ;a.g.e.c.
       rrf     X,F     ;.h.f.d.b
                       ;.a.g.e.c

       addwf   X,F     ;ahgfedcb
;
       rlf     X,W
       rlf     X,F     ;hgfedcba
                       ;it can be replaced
                       ;with rlf X,W
                       ;if necessary...


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\02\06@185850 by jamesnewton

face picon face
This and several other versions (quickest, smallest, etc..) listed at

http://www.piclist.com/techref/microchip/math/bit/revbits.htm

---
James Newton (PICList Admin #3)
spam_OUTjamesnewtonTakeThisOuTspampiclist.com 1-619-652-0593
PIC/PICList FAQ: http://www.piclist.com or .org

{Original Message removed}

2001\02\06@192933 by Bob Ammerman

picon face
   rrf    InputReg,f
   rlf    OutputReg,f
   rrf    InputReg,f
   rlf    OutputReg,f
   rrf    InputReg,f
   rlf    OutputReg,f
   rrf    InputReg,f
   rlf    OutputReg,f
   rrf    InputReg,f
   rlf    OutputReg,f
   rrf    InputReg,f
   rlf    OutputReg,f
   rrf    InputReg,f
   rlf    OutputReg,f
   rrf    InputReg,f
   rlf    OutputReg,f

:-)

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...