64-bit division


Closed Thread
Results 1 to 16 of 16

Thread: 64-bit division

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Posts
    8

    Question 64-bit division

    I'm developing a hobby project involving a 16F886 and a DDS, and for this I need to divide a 64-bit number by a 32-bit number to get a 32-bit result. The problem is that I seem to be too mathematically challenged to come up with a way to do this!

    The division I need is unsigned.

    The 64 bit number is actually a 32 bit number shifted left, so that the right 32 bits are always zero.

    The actual numbers I will have for the dividend are in the range from 500,000 to 35,000,000 for the 32 MSBs (26 truly valid bits. The 6 MSBs stay at zero). That would be about 2*10^15 to 1.5*10^17 for the full 64 bit dividend, making it actually a 58 bit number.

    The divisor will be between 150,000,000 and 500,000,000, so this is actually a 29 bit number.

    The result I need to get will range from zero to about 1.5*10^9, so it's actually a 31 bit number.

    How can I do this, using the 16 bit divide function of PBP?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Have a look at this thread by Darell: http://www.picbasic.co.uk/forum/showthread.php?t=12433
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Aug 2010
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    Bruce,
    that assembly library should indeed solve my problem - if I ever manage to understand how to use it from PBP!

    I would prefer to do this with PBP's math functions, to keep the program nice and readable.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    If you figure out how to do it with straight PBP I doubt if it would be any more readable than
    INCLUDE "N-Bit_MATH.pbp"
    with a few lines of ASM added to your main code.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Aug 2010
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    Well, I'm trying to get that n-bit math to work for me. I downloaded and installed MPASMWIN (I hope that's the right one?), included the math library in my program, defined the three 64 bit variables, etc. So far I haven't been able to get it working, I'm still sorting through the learning curve.
    At this time I'm a bit stuck because MPASMWIN shows up, says it has found one error, has one warning, and 262 messages. When I press "OK", I have to quickly stop the stream to be able to even see the beginning, where the error is! The error is:

    Unable to exceute mpasmwin.

    The warning does not show up, and the messages are all about the code crossing page boundaries.

    I don't understand this. How is it that it can't execute mpasmwin, when mpasmwin is reporting that error??? Isn't this like the question of the hen and the egg?

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    To start with you probably need to use the MPASWIN that came with your PBP CD.
    Install MPLAB from the CD to the default place and MPASMWIN will be there. Sometimes the one downloaded will not work.

    Then I will guess that you are using Micro Code Studio as a code editor. Go to Tool on the tool bar and select compiler options then under the Assembler tab select MPASM.

    Then give it a try.
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 0

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