Searching \ for 'Bit Banging Beckoning' 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=bit+banging+beckoning
Search entire site for: 'Bit Banging Beckoning'.

Truncated match.
PICList Thread
'Bit Banging Beckoning'
1997\08\27@132159 by sdattalo

face
flavicon
face
Here's another PIC bit-banging challenge. Given a two-bit variable
create the three-bit variable:

  A   |    B
-------+--------
 00   |   000
 01   |   001
 10   |   011
 11   |   111

Bonus points to those who can:
 1) Keep A unchanged                  1 point
 2) Clear the remaining bits of B     1 points
 3) Isosynchronous execution          3 points
 4) Keep W unchanged                  5 points

Execution points:  15 - (maximum cycles to complete)

The best I found ran in 8-cycles and satisfied bonuses
1,2, and 3. Points = 15 - 8 + 1 + 1 + 3 = 12 points.

Hint:

 B = (2^A) - 1

Any takers?

Scott
--
"Life in two dimensions is a mass production scheme"
                                         Neil Peart

1997\08\27@144328 by sdattalo

face
flavicon
face
part 0 1187 bytes content-type:textReturn-Path: <spam_OUTsupercatTakeThisOuTspamVenus.mcs.net>
Received: from Kitten.mcs.com by unix.SRI.COM (SMI-8.6/SMI-SVR4)
       id LAA23064; Wed, 27 Aug 1997 11:27:17 -0700
Received: from Venus.mcs.net (.....supercatKILLspamspam@spam@Venus.mcs.net [192.160.127.92]) by
Kitten.mcs.com (8.8.5/8.8.2) with ESMTP id NAA23749 for
<sdattalospamKILLspamunix.SRI.COM>; Wed, 27 Aug 1997 13:27:13 -0500 (CDT)
Received: (from supercat@localhost) by Venus.mcs.net (8.8.5/8.8.2) id NAA22816
for .....sdattaloKILLspamspam.....unix.SRI.COM; Wed, 27 Aug 1997 13:27:12 -0500 (CDT)
From: John Payson <EraseMEsupercatspam_OUTspamTakeThisOuTMcs.Net>
Message-Id: <199708271827.NAA22816spamspam_OUTVenus.mcs.net>
Subject: Re: Bit Banging Beckoning
To: @spam@sdattaloKILLspamspamunix.SRI.COM
Date: Wed, 27 Aug 1997 13:27:11 -0500 (CDT)
In-Reply-To:  <KILLspam34046293.3FECKILLspamspamunix.sri.com> from "Scott Dattalo" at Aug 27, 97
10:23:31 am
X-Mailer: ELM [version 2.4 PL24]
Content-Type: text

>    A   |    B
> -------+--------
>   00   |   000
>   01   |   001
>   10   |   011
>   11   |   111

       clrf    B
       btfsc   A,1
       bsf     B,0
       btfsc   A,1
       bsf     B,1
       bsf     C
       btfsc   A,0
        rlf    B

Should be 17 points I think, right?


1997\08\27@144943 by Martin R. Green

picon face
Just a quick first pass:

Assume A & B are register files.

This one preserves W but could take longer (depends on A).

       CLRF B
       MOVF A,1
       BTFSC STATUS, ZERO
       GOTO LBL2
LBL1:
       BSF STATUS, CARRY
       RLF B
       DECFSZ A,1
       GOTO LBL1
LBL2:

This one is very short but doesn't preserve W (but does preserve A).

ENTRY:
       MOVF A
       CALL CONVERT
       MOVWF B
       ; done

CONVERT:
       ADDWF PCL,1
       RETLW 0
       RETLW 1
       RETLW 3
       RETLW 7

By modifying the code just after ENTRY we can preserve everything.

ENTRY:
       MOVWF B
       MOVF A
       CALL CONVERT
       XORWF B,1
       XORWF B,0
       XORWF B,1
       ; done

I think the last one satisfies all your criteria, but I don't know what
Isosynchronous execution is.


CIAO - Martin R. Green
RemoveMEelimarTakeThisOuTspambigfoot.com

----------
From:   Scott Dattalo[SMTP:spamBeGonesdattalospamBeGonespamunix.SRI.COM]
Sent:   Wednesday, August 27, 1997 1:23 PM
To:     TakeThisOuTPICLISTEraseMEspamspam_OUTmitvma.mit.edu
Subject:        Bit Banging Beckoning

Here's another PIC bit-banging challenge. Given a two-bit variable
create the three-bit variable:

  A   |    B
-------+--------
 00   |   000
 01   |   001
 10   |   011
 11   |   111

Bonus points to those who can:
 1) Keep A unchanged                  1 point
 2) Clear the remaining bits of B     1 points
 3) Isosynchronous execution          3 points
 4) Keep W unchanged                  5 points

Execution points:  15 - (maximum cycles to complete)

The best I found ran in 8-cycles and satisfied bonuses
1,2, and 3. Points = 15 - 8 + 1 + 1 + 3 = 12 points.

Hint:

 B = (2^A) - 1

Any takers?

Scott
--
"Life in two dimensions is a mass production scheme"
                                         Neil Peart

1997\08\27@183707 by Mike Keitz

picon face
On Wed, 27 Aug 1997 11:44:49 -0700 Scott Dattalo <RemoveMEsdattalospamTakeThisOuTunix.SRI.COM>
writes:

>From: John Payson <supercatEraseMEspam.....Mcs.Net>
>
>>    A   |    B
>> -------+--------
>>   00   |   000
>>   01   |   001
>>   10   |   011
>>   11   |   111
>
>        clrf    B
>        btfsc   A,1
>        bsf     B,0
>        btfsc   A,1
>        bsf     B,1
>        bsf     C
>        btfsc   A,0
>         rlf    B
>
>Should be 17 points I think, right?
>
Under Scott's rules John's code is probably the best on points.  If
willing to modify W, 2 instructions and 2 cycles could be taken off:

       rrf     A,w
       movwf   B
; B(C) here : 000(0) 000(1) 001(0) 001(1)
       btfsc   A,1
       bsf     B,1
; B(C) here : 000(0) 000(1) 011(0) 011(1)
       btfsc   A,0
       rlf     B,f
; B(C) here : 000(0) 001(0) 011(0) 111(0)

Another 6 instr, 6 cycle solution; this one modifies W and A, placing the
result back in A rather than a seperate RAM location B :

       comf    A,w
       andlw   b'00000011'     ;See if A = 11.
       skpnz                   ;Skip if it isn't.
       bsf     A,2             ;Convert 11 to 111.
       btfsc   A,1             ;If A1 = 1, then B0 must be 1...
       bsf     A,0             ; so convert 10 to 011.

Not bad, until you see the next one, perhaps the ultimate in instruction
/ cycle count - only 4.  This one also trashes W and converts A in place,
though with 2 more cycles it could leave A unchanged and create B
seperately, making it equivalent to my first example.

       incf    A,w
       iorlw   b'00000001'     ;W[A] : 001 011 011 101
       btfsc   A,1             ;If A < 2, it's OK as is.
       iorwf   A,f             ;Otherwise set some more bits.

1997\08\27@185200 by Mike Keitz

picon face
I wrote:

>       incf    A,w
>       iorlw   b'00000001'     ;W[A] : 001 011 011 101
>       btfsc   A,1             ;If A < 2, it's OK as is.
>       iorwf   A,f             ;Otherwise set some more bits.

Actually this one was rushed out- it is unnecessary to set bit 0 in the
mask; so it can be improved to just:
       incf    A,w
       btfsc   A,1     ;W[A] : 001 010 011 100
       iorwf   A,f
; Old A : 000 001 010 011
; New A : 000 001 011 111

The version that doesn't change A, storing B in another RAM would be:
       movfw   A
       movwf   B
       incf    A,w
       btfsc   A,1
       iorwf   B,f

which is 15 points but I think the penalty for changing W is too high.

1997\08\27@203306 by rlunn

flavicon
face
Scott Dattalo challenged:

>    A   |    B
> -------+--------
>   00   |   000
>   01   |   001
>   10   |   011
>   11   |   111

Mike Keitz replied:

> .. perhaps the ultimate in instruction / cycle count - only 4.
>
>         incf    A,w
>         iorlw   b'00000001'     ;W[A] : 001 011 011 101
>         btfsc   A,1             ;If A < 2, it's OK as is.
>         iorwf   A,f             ;Otherwise set some more bits.

Which leads me to notice:

               incf    A,w                             ; result in 'A' (trash W
)
               btfsc   A,1
               iorwf   A,f

or...

               incf    A,w                             ; result in W
               btfsc   A,1
               iorwf   A,w

___Bob

1997\08\27@214529 by sdattalo

face
flavicon
face
Robert Lunn wrote:

> Mike Keitz replied:
>
> > .. perhaps the ultimate in instruction / cycle count - only 4.
> >
> >         incf    A,w
> >         iorlw   b'00000001'     ;W[A] : 001 011 011 101
> >         btfsc   A,1             ;If A < 2, it's OK as is.
> >         iorwf   A,f             ;Otherwise set some more bits.
>
> Which leads me to notice:
>
>                 incf    A,w                             ; result in 'A' (trash
W)
>                 btfsc   A,1
>                 iorwf   A,f

But not before Mike Keitz wrote the same thing:
>
> Actually this one was rushed out- it is unnecessary to set bit 0 in the
> mask; so it can be improved to just:
>         incf    A,w
>         btfsc   A,1     ;W[A] : 001 010 011 100
>         iorwf   A,f
> ; Old A : 000 001 010 011
> ; New A : 000 001 011 111

And then Bob went on to write
> or...
>
>                 incf    A,w                             ; result in W
>                 btfsc   A,1
>                 iorwf   A,w

Which I thought of too (after Mike's post of course) only to realize
that it doesn't work. Consider the case A=0.

Mike's 3-cycle solution is superb! But keep in mind that it does
assume that the 6 msbs of A are zeroes. But we can strike two
points with a 'BCF  A,2' instruction before his code.

And then Mike wrote:
> ... I think the penalty for changing W is too high.

Yeah, I agree. I only threw it in there because I didn't see an
easy way to not trash W and to still have efficient code.

And in his solutions, Martin R. Green wrote:
> I think the last one satisfies all your criteria, but I don't know what
>  Isosynchronous execution is.

"Isosynchronous execution" means that the execution time is constant
regardless of the path through the algorithm. Isosynchronous code is
very useful for time sensitive applications.


In a private e-mail to Andy Warren I wrote:

The REAL reason I put this out as a challenge is that I'm
writing a software PWM that has single cycle resolution. I needed
to convert the lower two bits of the pulse width into the
string of 1's (according to that formula B = 2^A - 1). I have
a solution, but I thought it was an interesting enough problem
to be posed as a challenge. Besides I'm getting a little tired
of the non-PIC shullbit.  <<< EXPLICATIVE REARRANGED >>>

Once I have 'B', I can then execute this isosynchronous phase delay:

   BTFSS   B,0
    goto   $+1
   BTFSS   B,1
    goto   $+1
   BTFSS   B,2
    goto   $+1

  ;Execute phase delayed code here

   BTFSC   B,0
    goto   $+1
   BTFSC   B,1
    goto   $+1
   BTFSC   B,2
    goto   $+1

The entry and exit blocks both execute in 6 to 9 cycles.
However, the sum of their execution times is a constant 15 cycles.


BTW, here's my 7-cycle solution (assumes upper 6-bits of A are zero)

   RLF    A,W
   ANDWF  A,W
   BTFSC  A,1
    ADDLW 3
   IORWF  A,W
   ANDLW  7
   MOVWF  B

Interesting perhaps, but not as fast as Mike's or clean as John's.
Good work guys.

Scott

1997\08\28@001553 by Bob Newhart

picon face
Scott Dattalo tried to tell me...

>Here's another PIC bit-banging challenge. Given a two-bit variable
>create the three-bit variable:
>
>   A   |    B
>-------+--------
>  00   |   000
>  01   |   001
>  10   |   011
>  11   |   111
>
>Bonus points to those who can:
>  1) Keep A unchanged                  1 point
>  2) Clear the remaining bits of B     1 points
>  3) Isosynchronous execution          3 points
>  4) Keep W unchanged                  5 points
>
>Execution points:  15 - (maximum cycles to complete)

Here's my code:

out       goto      Done

start     btfss     A, 1
         goto      out
         btfsc     A, 0
         bsf       A, 2
         bsf       A, 0

Done      whatever

This scores 18
cycles - 5 (15 -5 = 10)
isosynchronous      3
w intact            5

I'm assuming that the rest bit 2 of A is clear initially.  If it's not,
insert the following
at start:

start     movlw     kMASK
         xorwf     A, F

for a new score of 12

or, insert this at start

start     bcf       A, 2

for a new score of 17

Jason

1997\08\28@011412 by rlunn

flavicon
face
> And then Bob went on to write
> > or...
> >
> >                 incf    A,w           ; result in W
> >                 btfsc   A,1
> >                 iorwf   A,w
>
> Which I thought of too (after Mike's post of course) only to
> realize that it doesn't work. Consider the case A=0.

Of course.

Leaving 'A' unchanged, and the result in W, can be done in four
cycles using Mike's approach:

               clrw
               btfsc    A,1
               incf     A,w
               iorwf    A,w

___Bob

1997\08\28@112642 by Martin R. Green

picon face
Thanks, actually, the answer to my question hit me exactly like a soft boiled
egg doesn't ten minutes after I posted the question.


CIAO - Martin R. Green
EraseMEelimarspambigfoot.com

----------
From:   Scott Dattalo[SMTP:RemoveMEsdattaloEraseMEspamEraseMEunix.SRI.COM]
Sent:   Wednesday, August 27, 1997 9:06 PM
To:     RemoveMEPICLISTspam_OUTspamKILLspammitvma.mit.edu
Subject:        Re: Bit Banging Beckoning

Robert Lunn wrote:


And in his solutions, Martin R. Green wrote:
> I think the last one satisfies all your criteria, but I don't know what
>  Isosynchronous execution is.

"Isosynchronous execution" means that the execution time is constant
regardless of the path through the algorithm. Isosynchronous code is
very useful for time sensitive applications.

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