I need some easy way to divide 64b unsigned integers in assembler for x86. My number is saved in two 32b registers EDX:EAX and I need to put result back to EDX:EAX. Factor is in 32b integer. Some code, please?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If I interpret your question correctly (particularly the part
Factor is in 32b integer), you want to divide a 64-bit dividend by a 32-bit divisor and get a 64-bit quotient.If that interpretation is correct, then it’s actually easy to do in 32-bit code.
The idea is that you divide both “halves” of the dividend by the divisor and reuse the remainder from the first division for the second division.
C code illustrating how to do it:
Output (ideone):
And now the equivalent division code in assembly (NASM syntax) without checking for division by 0: