Bits and pieces


+ Reply to Thread
Results 1 to 3 of 3

Thread: Bits and pieces284 days old

  1. #1
    Member flosigud's Avatar
    Join Date
    Oct 2013
    Posts
    203
    Thumbs Up
    Received: 13
    Given: 15
    Total Downloaded
    3.20 GB

    1 Not allowed!

    Default Bits and pieces

    Some time ago somone, here on this board had to move few bit from one register to another and had solved it by using BitSet and BitTest to do that, but somewhere in the back of his mind he had a recollection of something more clever involving xor, and and bitmask. Many others remembered as much, but not more, me included.

    I googled how to do this in PIC assembler and this is what I found, wrapped in precompiler macro.

    Code:
    $define CopyBits(bitmask,from_file,to_file) '
        Movf    from_file,w                        '
        Xorwf    to_file,w                        '
        Andlw    bitmask                        '
        Xorwf    to_file,f
    This works nicely but wouldn't it be nicer to have it in Proton:


    Code:
    $define CopyBits(bitmask,from_file,to_file)    '
        WREG = to_file ^ from_file                '
        WREG = WREG & bitmask                    '
        to_file = to_file ^ WREG
    This compiles to this:


    Code:
    F1_000123 equ $ ; IN [COPYB.BAS] WREG = BTMP2 ^ BTMP1
        movf bTmp1,W,0
        xorwf bTmp2,W,0
        andlw 7
        xorwf bTmp2,F,0
    That's same as the assembler code we started with.


    So if you have more than two bits to move from one register to another this is more efficient
    Flosi Guđmundsson
    Reykjavík

  2. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,685
    Thumbs Up
    Received: 357
    Given: 173
    Total Downloaded
    2.00 GB

    0 Not allowed!

    Default Re: Bits and pieces

    I've always taken pride in the tightness and efficiency of the compiler's assemby it creates, and it is really good to see someone appreciate it. :-)

    The $define's code written in Proton BASIC also manages RAM banks if the variables are not in the same bank, but the raw assembler version does not, which will actually cause a program to fail in certain circumstances but a lot of writers of Asm do not realise this.

  4. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Member flosigud's Avatar
    Join Date
    Oct 2013
    Posts
    203
    Thumbs Up
    Received: 13
    Given: 15
    Total Downloaded
    3.20 GB

    0 Not allowed!

    Default Re: Bits and pieces

    When looking for solutions of hardware problems, I often look over the shoulders of our assembler friends. They often have the simplest solutions, that translate well to Proton
    Flosi Guđmundsson
    Reykjavík

  6. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. 64 Bits Variable
    By teo in forum Proton Plus Compiler v3
    Replies: 8
    Last Post: 12th January 2015, 09:29
  2. About Configuration Bits
    By eleckits in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 5th June 2007, 10:15
  3. [SOLVED !] Bits and Bytes
    By fgcity in forum Proton Plus Compiler v3
    Replies: 22
    Last Post: 25th May 2007, 13:08
  4. bytes and bits
    By fgcity in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 11th May 2007, 10:19
  5. [SOLVED !] High Bits' and Low Bits
    By cotang in forum Proton Plus Compiler v3
    Replies: 7
    Last Post: 8th April 2006, 05:48

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts