This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

c code for division of 32bit/32bit no

i want to divide 32bit/32bit no i don't know the procedure so
pls send me the procedure who to divide

Parents
  • There are several algorithms for doing this. You could just look at how the library code does this.

    Do a web search for "32 bit divide algorithms ARM", or more general, divide algorithms.

    The main thing is to generate the inverse of a number, like 1 / D. Here's a sample algorithm:

    Q0 = estimated quotient (from a table)

    Then repeat this sequence until you get enough bits of precision

    Q1 = Q0(2 - (Q0 x D))
    Q2 = Q1(2 - (Q1 x D))
    Q3 = Q2(2 - (Q2 x D))
    Q4 = Q3(2 - (Q3 x D))

    Note this sequence is what would be done for fixed or floating point numbers. For integers, you'd have to scale the results to keep them within a 32 bit range.

    I can't remember the exact rate precision increase for each step, but 4 iterations are enough if you start with 8 bits of precision or more from a table.

    There are some clever tricks to optmize this by unfolding loops and scaling thing properly.

Reply
  • There are several algorithms for doing this. You could just look at how the library code does this.

    Do a web search for "32 bit divide algorithms ARM", or more general, divide algorithms.

    The main thing is to generate the inverse of a number, like 1 / D. Here's a sample algorithm:

    Q0 = estimated quotient (from a table)

    Then repeat this sequence until you get enough bits of precision

    Q1 = Q0(2 - (Q0 x D))
    Q2 = Q1(2 - (Q1 x D))
    Q3 = Q2(2 - (Q2 x D))
    Q4 = Q3(2 - (Q3 x D))

    Note this sequence is what would be done for fixed or floating point numbers. For integers, you'd have to scale the results to keep them within a 32 bit range.

    I can't remember the exact rate precision increase for each step, but 4 iterations are enough if you start with 8 bits of precision or more from a table.

    There are some clever tricks to optmize this by unfolding loops and scaling thing properly.

Children
  • "Do a web search for '32 bit divide algorithms ARM'..."

    Why would he search for ARM algorithms when he's using C51?

    Why, in fact, search for anything at all when C51 supports 32-bit data types anyhow?!
    As would any ARM 'C' compiler!

    All this has already been said as nauseam in his many cross-posts - hence the preceding posts, PLEASE stop answering posts from this idiot, maybe he will go away - and it appears that he has gone away!