Searching \ for 'Code Challange' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=code+challange
Search entire site for: 'Code Challange'.

Truncated match.
'Code Challange'
1999\04\17@025639 by

Hi There!
I will try and improve the s/n ratio.
We haven't had a challenge for a while now so here it go's.

I have a register say RegA that contains 8 bits in the following order

1 2 3 4 5 6 7 8

I want to reverse the order to look like this

8 7 6 5 4 3 2 1

The result does not have to be in RegA
The code i could think of follows

rlf  RegA,f
rrf  RegB,f
rlf  RegA,f
rrf  RegB,f
rlf  RegA,f
rrf  RegB,f
rlf  RegA,f
rrf  RegB,f
rlf  RegA,f
rrf  RegB,f
rlf  RegA,f
rrf  RegB,f
rlf  RegA,f
rrf  RegB,f
rlf  RegA,f
Is there a faster and shorter way of doing this?

Zack

E-Mail: spazzmaniname.com

One regrets more the things that you
did not do than the things you did do.

Try this

clrf regB
btfsc regA,0
bsf regB,7
btfsc regA,1
bsf regB,6
btfsc regA,2
bsf regB,5
btfsc regA,3
bsf regB,4
btfsc regA,4
bsf regB,3
btfsc regA,5
bsf regB,2
btfsc regA,6
bsf regB,1
btfsc regA,7
bsf regB,0

If the bit is zero, skipping occurs and time is saved. The maximum time
occure if there are 7 1's.

Pailoor

Zack Cilliers wrote:

{Quote hidden}

--
=================================================
For Embedded Controls Solutions and Custom Designs

CHIP TECHNOLOGIES - Member, Microchip Consultant Program
Bangalore - INDIA

Email   : chiptechvsnl.com
Webpage : http://business.vsnl.com/chiptech ( updated 16th April 1999 )

>
> If the bit is zero, skipping occurs and time is saved. The maximum time
> occure if there are 7 1's.

Nope, the skipped instruction still takes the same time, so your
code is actually isosynchronous (takes always the same amount of time).

Wouter.

Wouter,  you are right, somethings gone into my head.

It is saterday evening here ;-)

pailoor

w. v. ooijen / f. hanneman wrote:

> >
> > If the bit is zero, skipping occurs and time is saved. The maximum time
> > occure if there are 7 1's.
>
>  Nope, the skipped instruction still takes the same time, so your
> code is actually isosynchronous (takes always the same amount of time).
>
> Wouter.

--
=================================================
For Embedded Controls Solutions and Custom Designs

CHIP TECHNOLOGIES - Member, Microchip Consultant Program
Bangalore - INDIA

Email   : chiptechvsnl.com
Webpage : http://business.vsnl.com/chiptech ( updated 16th April 1999 )

At 15:37 04/17/99 +0530, Ravi Pailoor wrote:
>Try this
>
>  clrf regB
>  btfsc regA,0
>  bsf regB,7
>  btfsc regA,1
[...]
>  btfsc regA,7
>  bsf regB,0
>
>If the bit is zero, skipping occurs and time is saved. The maximum time
>occure if there are 7 1's.

how that? with which processor? doesn't the btfsc instruction take 2 cycles
when skipping?

ge

>I have a register say RegA that contains 8 bits in the following order
>
>1 2 3 4 5 6 7 8
>
>I want to reverse the order to look like this
>
>8 7 6 5 4 3 2 1

... a slower way

movlw 0x80
movwf RegB
do_next_bit
rlf RegA,f
rrf RegB,f
btfss STATUS,C
goto do_next_bit

Ken

I have some common code to do a large number of similar
things. Basically it does a 16 byte  'lookup' <addwf pcl> on each
fourbit nibble <using swapf> and reassembles it as necessary.

I use this to: find # of first bit in byte, find last, count bits in
byte,
calculate 'parity' of byte, quickly 'sample' for bit patterns <i.e.
just the 'even' numbered bits packed together >and a few others
I don't recall.. Essentially this trades speed for space (if you have
the space).

Details left up to you; or e-mail me.

To convince yourself you 'got' it, notice that a 4 X 4 bit
multiply can be done with one 256 byte 'lookup'
< or only 224 bytes if you skip the  x 0 and x 1 cases>
so an 8 x 8 just requires 4 such lookups. <Factoring bytes to
nibbles as (A+B) X (C+D) remember 'long' multiplication >
I  suspect this is nearly the 'fastest'  8 X 8 to 16 bits multiply on
the
PIC. but haven't worked it out in detail. Code, anyone???

R.Martin

Hi,

;16 cycles, destroys RegA, result in RebB

rlf RegA,f
rrf RegB,f
rlf RegA,f
rrf RegB,f
rlf RegA,f
rrf RegB,f
rlf RegA,f
rrf RegB,f
rlf RegA,f
rrf RegB,f
rlf RegA,f
rrf RegB,f
rlf RegA,f
rrf RegB,f
rlf RegA,f
rrf RegB,f

regards,
Reggie

You are right Gerhard,  It was a saturday evening here when I wrote the reply
;-)

Pailoor

Gerhard Fiedler wrote:

{Quote hidden}

--
=================================================
For Embedded Controls Solutions and Custom Designs

CHIP TECHNOLOGIES - Member, Microchip Consultant Program
Bangalore - INDIA

Email   : chiptechvsnl.com
Webpage : http://business.vsnl.com/chiptech ( updated 16th April 1999 )

> I have a register say RegA that contains 8 bits in the following order
>
> 1 2 3 4 5 6 7 8
>
> I want to reverse the order to look like this
>
> 8 7 6 5 4 3 2 1
>

Mike Keitz posed a challenge in late 1997 to reverse 7-bits in a
byte. Mike's summary of solutions is at:
http://www.iversoft.com/piclist/9710/1805.shtml

- Andy.

----------------------------------------------------------
Andrew David, Software Manager, Ultronics Ltd, Cheltenham.
akdavidUltronics.co.uk          http://www.ultronics.com/
----------------------------------------------------------

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