How do you divide numbers larger than a register in assembly?

  • Thread starter Thread starter mtanti
  • Start date Start date
  • Tags Tags
    Assembly Division
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 7K views
mtanti
Messages
172
Reaction score
0
First of all i'de like to know if there is an efficiant algorithm which assembly uses to divide two numbers.
Second I'de like to know how do you divide numbers which don't fit into a register. I'm talking about an array of bytes in RAM to be divided.

10x!
 
Physics news on Phys.org
mtanti said:
First of all i'de like to know if there is an efficiant algorithm which assembly uses to divide two numbers.
Second I'de like to know how do you divide numbers which don't fit into a register. I'm talking about an array of bytes in RAM to be divided.

10x!

Well, you could use multi-precision arithmetic if it's really large numbers or very high precision. I tell you what though, that would be quite a neat challenge in assembly. What about just C++? You know that's pretty close to assembly speed. Anyway, just search the web for "multi-precision arithmetic". The algorithm is straight-forward and intuitive once you work with it for a while.

As far as what assembly does, 2's compliments come to mind but I'd really have to review on that one.
 
In ASM you can do integer division by using DIV. If you want to do floating point division use FDIV.

Here is a C library for doing arbitrary precision arithmetic:

http://www.swox.com/gmp/index.orig.html

There are more specialized libraries depending on how many bits of precision you really need. This is just a general case library.
 
Last edited by a moderator: