Searching \ for '"Mirror image" a byte' 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/index.htm?key=mirror+image+byte
Search entire site for: '"Mirror image" a byte'.

Truncated match.
PICList Thread
'"Mirror image" a byte'
2002\10\10@124921 by Sam S Man

flavicon
face
Hi all
Can anyone help improve the code below. I need a "mirror image" of a byte.
For example b7,b6,b5,b4,b3,b2,b1,b0 will become b0,b1,b2,b3,b4,b5,b6,b7....
in the shortest time possible!! AND if possible no B and C....result in w.


A= the file, B = the "mirror image", C=8

   clrf    B
X
   rlf    A,f
   rrf    b,f
   decfsz    C,f
   goto    X
   goto    done

--
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


2002\10\10@132633 by Pic Dude

flavicon
face
Check the piclist archives -- I has asked something very similar earlier
this year, and there were a lot of awesomely-optimized solutions.  My
purpose was to flip the bits for output to LED's, since it was easier to
route the PCB traces.

Cheers,
-Neil.



> {Original Message removed}

2002\10\10@134428 by Wagner Lipnharski

flavicon
face
Sam S Man wrote:
> Hi all
> Can anyone help improve the code below. I need a "mirror image" of a
> byte. For example b7,b6,b5,b4,b3,b2,b1,b0 will become
> b0,b1,b2,b3,b4,b5,b6,b7.... in the shortest time possible!! AND if
> possible no B and C....result in w.
>
>
> A= the file, B = the "mirror image", C=8
>
>     clrf    B
> X
>     rlf    A,f
>     rrf    b,f
>     decfsz    C,f
>     goto    X
>     goto    done


256 bytes table is the fastest possible solution.
Perhaps a 2x 16 nibbles table, but will take at least twice the 256 bytes
table time.

VV46NER

--
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


2002\10\10@140219 by Bob Ammerman

picon face
A very simple technique is to unroll the loop:

   rlf    A,f
   rrf    B,f
   rlf    A,f
   rrf    B,f
   rlf    A,f
   rrf    B,f
   rlf    A,f
   rrf    B,f
   rlf    A,f
   rrf    B,f
   rlf    A,f
   rrf    B,f
   rlf    A,f
   rrf    B,f
   rlf    A,f
   rrf    B,W

Still needs B however, and there may be a faster way.

Bob Ammerman
RAm Systems

{Original Message removed}

2002\10\10@140429 by Wagner Lipnharski

flavicon
face
Sam S Man wrote:
> Hi all
> Can anyone help improve the code below. I need a "mirror image" of a
> byte. For example b7,b6,b5,b4,b3,b2,b1,b0 will become
> b0,b1,b2,b3,b4,b5,b6,b7.... in the shortest time possible!! AND if
> possible no B and C....result in w.
>
>
> A= the file, B = the "mirror image", C=8
>
>     clrf    B
> X
>     rlf    A,f
>     rrf    b,f
>     decfsz    C,f
>     goto    X
>     goto    done

Ah, forgot to say, do you have by any chance two 8 bits port available?
Just hardwire them bit mirrored, output in A - mirrored input in B.

You can do it using one single 8 bits port, just hardwire lower 4 bits
mirrored to the higher 4 bits.  When higher 4 bits as output, you have it
mirrored at the lower 4 bits as input, then lower 4 bits as output, will
mirror at the 4 high input bits. And/Or the input, voilá.

Also, by software doesn't mean you need to rotate it.
There are certain combinations of bits that will not mirror at all.
00, FF, 18, 24, 3C, 42, 66, 7E, 81, A5, C3, E7...  it would be possible to
detect and convert faster than 8 rotates?

In theory, the following logic uses only 7 operations, faster than rotate;

ABCD  EFGH
   \/
   /\       swap
EFGH  ABCD
\/
/\          swap
GHEF  ABCD
      \/
      /\    swap
GHEF  CDAB
X            swap
HGEF
 X          swap
HGFE  CDAB
     X      swap
     DCAB
       X    swap
HGFE  DCBA


VV46NER

--
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


2002\10\10@141048 by Jan-Erik Soderholm

face picon face
There is a real fast, hardware based solution, if you have the spare ports.
Wire up on 8-bit port to another 8-bit port with the bits in reverse order.
Then (with the value to be "mirrored" in W) just :

movwf       ! to the "output" port.
movf         ! from the "input" port back to W.

Can't run much faster than that !!

Jan-Erik Svderholm
S:t Anna Data
Sweden
tel : +46 121 42161
mob : +46 70 5241690

--
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


2002\10\10@141846 by Sam S Man

flavicon
face
no..no HW...
and just how would you write that SWAP solution in code??

----- Original Message -----
From: "Wagner Lipnharski" <spam_OUTwagnerTakeThisOuTspamUSTR.NET>
To: <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU>
Sent: Friday, October 11, 2002 2:02 AM
Subject: Re: "Mirror image" a byte


Sam S Man wrote:
{Quote hidden}

Ah, forgot to say, do you have by any chance two 8 bits port available?
Just hardwire them bit mirrored, output in A - mirrored input in B.

You can do it using one single 8 bits port, just hardwire lower 4 bits
mirrored to the higher 4 bits.  When higher 4 bits as output, you have it
mirrored at the lower 4 bits as input, then lower 4 bits as output, will
mirror at the 4 high input bits. And/Or the input, voila.

Also, by software doesn't mean you need to rotate it.
There are certain combinations of bits that will not mirror at all.
00, FF, 18, 24, 3C, 42, 66, 7E, 81, A5, C3, E7...  it would be possible to
detect and convert faster than 8 rotates?

In theory, the following logic uses only 7 operations, faster than rotate;

ABCD  EFGH
   \/
   /\       swap
EFGH  ABCD
\/
/\          swap
GHEF  ABCD
      \/
      /\    swap
GHEF  CDAB
X            swap
HGEF
 X          swap
HGFE  CDAB
     X      swap
     DCAB
       X    swap
HGFE  DCBA


VV46NER

--
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

--
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


2002\10\10@145622 by mike

flavicon
face
This way preserves W, and doesn't use register C :

   clrf B
 bsf B,7
loop
rlf A
rrf B
skpc
goto loop

On Fri, 11 Oct 2002 00:35:11 +0800, you wrote:

{Quote hidden}

--
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


2002\10\11@045310 by o-8859-1?Q?Tony_K=FCbek?=

flavicon
face
Hi, take a look at:

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



/Tony

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\10\11@105453 by Roman Black

flavicon
face
Jan-Erik Soderholm wrote:
>
> There is a real fast, hardware based solution, if you have the spare ports.
> Wire up on 8-bit port to another 8-bit port with the bits in reverse order.
> Then (with the value to be "mirrored" in W) just :
>
> movwf       ! to the "output" port.
> movf         ! from the "input" port back to W.
>
> Can't run much faster than that !!



I can just imagine all the real world PIC
applications using 16 dedicated I/O pins just
to speed up the process of reversing a byte.
Lets see, now you need a 16F873 to do the job
of a 12C508! <grin>
-Roman

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\10\11@112650 by M. Adam Davis

flavicon
face
Just be aware of timing issues.

IIRC, port reads are done at an early cycle, while writes are done at
the end.

Depending on the speed you may need a nop in there.

-Adam

Jan-Erik Soderholm wrote:

{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\10\11@114152 by Sam S Man

flavicon
face
Thanks Tony.. that really helps..
tq again.

----- Original Message -----
From: "Tony K|bek" <tony.kubekspamKILLspamFLINTAB.COM>
To: <.....PICLISTKILLspamspam.....MITVMA.MIT.EDU>
Sent: Friday, October 11, 2002 4:51 PM
Subject: Re: "Mirror image" a byte


Hi,
take a look at:

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



/Tony

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\10\12@003650 by Wagner Lipnharski

flavicon
face
M. Adam Davis wrote:
> Just be aware of timing issues.
>
> IIRC, port reads are done at an early cycle, while writes are done at
> the end.
>
> Depending on the speed you may need a nop in there.
>
> -Adam
>
> Jan-Erik Soderholm wrote:
>

So you mean that Microchip probably invented the "time machine"?
You can read in the port output echoed much before you actually put data
out?
:)

VV46NER

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspam_OUTspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body


2002\10\12@074046 by =?iso-8859-1?Q?F=E1bio_Pereira?=

flavicon
face
I think M. Adam wanted to say that the MOVWF instruction will write the data
at the end of it's instruction cycle (Q4) and the next instruction (MOVF)
will read the data on the beginning of it's instruction cycle (Q2).
This will leave only one clock cycle between writing and reading the data.
Depending on the clock frequency used, maybe there is not enough time to
data stabilize (the old problem of R-M-W instructions). And then, a NOP will
be needed between the two MOVs.

Regards,

Fabio Pereira

{Original Message removed}

2002\10\12@105800 by Wagner Lipnharski

flavicon
face
Fábio Pereira wrote:
> I think M. Adam wanted to say that the MOVWF instruction will write
> the data at the end of it's instruction cycle (Q4) and the next
> instruction (MOVF) will read the data on the beginning of it's
> instruction cycle (Q2). This will leave only one clock cycle between
> writing and reading the data. Depending on the clock frequency used,
> maybe there is not enough time to data stabilize (the old problem of
> R-M-W instructions). And then, a NOP will be needed between the two
> MOVs.
>
> Regards,
>
> Fabio Pereira

I saw that, I just made funny of the tricky point of view.
For the ones that doesn't understand metal and silicon area charge timming
(capacitive delays) and propagation speed, it could sounds like the next
instruction would happens before the previous was completed, reinforcing
Einsten theory that in high speed you don't travel to the future, the
future comes to you in one speed or another, but it IS comming.

:)

VV46NER

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body


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