Quickest way to get highest set bit on port in to a variable?


Results 1 to 29 of 29

Threaded View

  1. #26
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Quickest way to get highest set bit on port in to a variable?

    Ok,
    In the listing he’s rotating left. I would think that would result in quicker times for the lower values.
    I’m pretty sure there’s an error in my asm, as the example uses a different instruction to rotate with carry.
    This is the same thing in BASIC but rotating right so the higher values should be found faster.
    I’d be interested to enter a race with it.. just not sure some lines are converted the way I’d want them to.

    Code:
    workword var word
    workbyte var workword.byte0 ‘ 1st byte
    bitcarry var workword.8 ‘ 9th bit
    bitcount var byte
    
    
    NCD8:
    bitcount = 8 ‘ mov l to w & w to f
    workbyte = portX ‘ mov l to w & w to f
    
    if workbyte = 0 then ‘ portX was zero
    goto whatawaste
    endif
    
    inloop:
    bitcount = bitcount - 1 ‘ decf
    workword = workword << 1 ‘ 2 x rrf with carry
    
    if bitcarry = 0 then ‘ btfss
    goto inloop ‘ goto
    endif
    return
    
    whatawaste:
    bitcount = 0 ‘ bsf
    return
    Last edited by Art; - 8th March 2015 at 18:24.

Similar Threads

  1. Replies: 6
    Last Post: - 18th July 2012, 03:42
  2. Whats the quickest way to set bits?
    By bearpawz in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 26th October 2010, 05:38
  3. Bit set question
    By nverma in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 2nd April 2007, 22:23
  4. set flags within a variable?
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 24th October 2006, 12:07
  5. How do I to set one bit in a register?
    By jessey in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th February 2006, 09:43

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

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