Searching \ for 'copying a bit' 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=copying+bit
Search entire site for: 'copying a bit'.

Truncated match.
PICList Thread
'copying a bit'
1999\08\02@171825 by Anne Ogborn

flavicon
face
I haven't found a clean way to say "copy a bit from here to there"
in PIC assembler.  This is my  current method, but surely there's
something more elegant.

  Here's an example, a loop that copies the
contents of buffer out RA4

wee
       rlf     buffer,f
       btfsc   STATUS,C        ; load the data
       bsf     PORTA,4
       btfss   STATUS,C
       bcf     PORTA,4
       nop
       bsf     clkp,clkn       ; toggle the clock
       nop
       bcf     clkp,clkn
       decfsz  numbits
       goto    wee

It's the  'load the data' part that seems horribly inelegant
Is there a better way?

--
Anniepoo
Need loco motors?
http://www.idiom.com/~anniepoo/depot/motors.html

1999\08\02@195427 by Scott Fink

picon face
part 0 1377 bytes
    wee
       bcf     PORTA,4
       rlf     buffer,f
       btfsc   STATUS,C        ; load the data
       bsf     PORTA,4
       nop
       bsf     clkp,clkn       ; toggle the clock
       nop
       bcf     clkp,clkn
       decfsz  numbits
       goto    wee

Not horribly clean, but saves all of one instruction.

Scott Fink
Microchip Technology
(see, we do look at the PIClist sometimes!)




______________________________ Reply Separator
_________________________________
Subject: copying a bit
Author:  spam_OUTPICLISTTakeThisOuTspamMITVMA.MIT.EDU (Anne Ogborn) at Internet_Exchange
Date:    8/2/99 2:15 PM


I haven't found a clean way to say "copy a bit from here to there"
in PIC assembler.  This is my  current method, but surely there's
something more elegant.

  Here's an example, a loop that copies the
contents of buffer out RA4

wee
       rlf     buffer,f
       btfsc   STATUS,C        ; load the data
       bsf     PORTA,4
       btfss   STATUS,C
       bcf     PORTA,4
       nop
       bsf     clkp,clkn       ; toggle the clock
       nop
       bcf     clkp,clkn
       decfsz  numbits
       goto    wee

It's the  'load the data' part that seems horribly inelegant
Is there a better way?

--
Anniepoo
Need loco motors?
www.idiom.com/~anniepoo/depot/motors.html
Attachment converted: wonderland:RFC-822.TXT (TEXT/CSOm) (0000B140)

1999\08\03@070610 by g.daniel.invent.design

flavicon
face
Anne, I think that four instructions *are* required:
You can simply change your code from:
>         btfsc   STATUS,C        ; load the data
>         bsf     PORTA,4
>         btfss   STATUS,C
>         bcf     PORTA,4
to:
COPY_BIT     MACRO   var_A,bit_N,var_B,bit_M
       NOEXPAND
        btfsc   var_A,1 << bit_N
        bsf     var_B,1 << bit_M
        btfss   var_A,1 << bit_N
        bcf     var_B,1 << bit_M
       ENDM

This will produce exactly the same output if called like this:

       COPY_BIT        STATUS,C,PORTA,4
but can be used on any current bank registers.

remember to define the dummy macro variables:
var_A   equ     0
bit_N   equ     0
etc....

Anne Ogborn wrote:
{Quote hidden}

--
Steam engines may be out of fashion, but when you consider that an
internal combustion engine would require recovery of waste heat by
transfer just before top dead centre then fashion becomes rather
redundant, USE STRATIFIED HEAT EXCHANGERS ! and external combustion.

You heard it first from: Graham Daniel, managing director of Electronic
Product Enhancements.
Phone NZ 04 387 4347, Fax NZ 04 3874348, Cellular NZ 021 954 196.

1999\08\03@085437 by Ian Rozowsky

flavicon
face
>         btfsc   STATUS,C        ; load the data
>         bsf     PORTA,4
>         btfss   STATUS,C
>         bcf     PORTA,4

Hi

The above fragment can be reduced to:

        bsf     PORTA,4
        btfss   STATUS,C
                bcf     PORTA,4

ie: Assume the  bit is one, then change to 0 if it is not. Saves 1
instruction.

Ian Rozowsky
Development Engineer
Centurion Systems
Box 506 Cramerview 2060 South Africa
Tel   : +27-11-708-2680
Fax   : +27-11-708-2630
e-mail: .....rozKILLspamspam@spam@centsys.co.za

1999\08\04@021159 by root

flavicon
face
Hi,

I'm afraid the macro below contains a bug. The idea is good, but think:

if bit_N e. g. would be 7 (it can be) 1 << 7 would be 128. The resulting
statement
       btfsc   var_A,128
may be in error.

I suggest to omit the 1<< term in the macro body.

Imre


On Tue, 3 Aug 1999, Graham Daniel wrote:

{Quote hidden}

1999\08\04@021618 by root

flavicon
face
Hi,

the solution below is generally good, but one should keep in mind a glitch
will be produced and it may be undesirable in certain situations.

Imre


On Tue, 3 Aug 1999, Ian Rozowsky wrote:

{Quote hidden}

1999\08\04@051617 by Miro

picon face
Here is an excerpt from Myke Predko's "Snippets" page
(http://www.myke.com/PICMicro/snippet.htm#No5):
.
.
.
5. Copy Bits from One Register to Another

Here is a fast way to save specific bits from one register into another.

      movf  Source, w
      xorwf Destination, w
      andlw B'xxxxxxxx'        ;  Replace "x" with "1" to Copy the Bit
      xorwf Destination
.
.
.

Miro

Miroslav Hibler
.....mhiblerKILLspamspam.....usa.net

____________________________________________________________________
Get free e-mail and a permanent address at http://www.netaddress.com/?N=1

1999\08\04@080403 by g.daniel.invent.design

flavicon
face
root wrote:
>
> Hi,
>
> I'm afraid the macro below contains a bug. The idea is good, but think:
>
> if bit_N e. g. would be 7 (it can be) 1 << 7 would be 128. The resulting

Good bug catching Immre,
I was thinking of an xor bit pattern location method and so used the 1
<<  shift method when it was not required.

1999\08\08@032238 by Scott Dattalo

face
flavicon
face
On Mon, 2 Aug 1999, Scott Fink wrote:

>
>      If your receiver system can tolerate a possible "spike" on the data
>      line (while the clock is in the inactive state) you can "pre-load" the
>      port pin:
>
>      wee
>         bcf     PORTA,4
>         rlf     buffer,f
>         btfsc   STATUS,C        ; load the data
>         bsf     PORTA,4
>         nop
>         bsf     clkp,clkn       ; toggle the clock
>         nop
>         bcf     clkp,clkn
>         decfsz  numbits
>         goto    wee
>
> Not horribly clean, but saves all of one instruction.

and if you wanna save another cycle and maintain the same level of
cleanliness:

     wee
        bcf     PORTA,4
        btfsc   buffer,7        ; load the data
         bsf    PORTA,4
        rlf     buffer,f        ;was a nop
        bsf     clkp,clkn       ; toggle the clock
        nop
        bcf     clkp,clkn
        decfsz  numbits
        goto    wee

and if you don't want to trash buffer:

     wee
        bcf     PORTA,4
        btfsc   buffer,7        ; load the data
         bsf    PORTA,4
        rlf     buffer,w        ;was a nop
        bsf     clkp,clkn       ; toggle the clock
        rlf     buffer,f
        bcf     clkp,clkn
        decfsz  numbits
        goto    wee

But there really isn't a clean way to copy a bit from one location to
another.

Scott

1999\08\09@125724 by Dmitry Kiryashov

flavicon
face
Hi Scott.

> But there really isn't a clean way to copy a bit from one
> location to another.

Actually I guess that you mean that there are alot of ways
to do it ;-)

WBR Dmitry.

1999\08\10@002922 by Gennette Bruce

flavicon
face
If you've got a few spare bytes then 2 test and forces can be used (a little
unsubtle, but it works)

  btfss  testfile,the_bit
  bcf   otherfile,otherbit
  btfsc  testfile,the_bit
  bsf   otherfile,otherbit

If the_bit is set then the code jumps the bcf, but performs the bsf (copies
the bit)
If the_bit is clear then the code performs the bcf, but jumps the bsf
(copies the bit)

Bye.

       -----Original Message-----
       From:   Dmitry Kiryashov [SMTP:EraseMEdkspam_OUTspamTakeThisOuTCARROLL.COM]
       Sent:   Tuesday, 10 August 1999 2:57
       To:     PICLISTspamspam_OUTMITVMA.MIT.EDU
       Subject:        Re: copying a bit

       Hi Scott.

       > But there really isn't a clean way to copy a bit from one
       > location to another.

       Actually I guess that you mean that there are alot of ways
       to do it ;-)

       WBR Dmitry.

1999\08\10@145041 by Mark Willis

flavicon
face
Seems to me that this would be 1 instruction shorter & 1 cycle quicker
if you just did either of these:

   bcf   otherfile,otherbit
   btfsc  testfile,the_bit
   bsf   otherfile,otherbit

 *or*

   bsf   otherfile,otherbit
   btfss  testfile,the_bit
   bcf   otherfile,otherbit

It's not like you need 2 tests <G>

 Mark  (Been offline, hope someone else saw this as well <G>)

Gennette Bruce wrote:
{Quote hidden}

>         {Original Message removed}

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