flat assembler
Message board for the users of flat assembler.
Index
> Main > How to divide two integers? 
Author 

comrade
Regarding dividing two integers using IDIV:
The source operand is, indeed, 64bit, but that does not mean you have to use all of them. The upper half of the 64bit QWORD divident is stored in EDX, and the lower in EAX. So simply put your integer in EAX, and use CDQ to extend it to EDX (if EAX is negative, EDX will be FFFFFFFF, if EAX is positive, EDX will be 0). IDIV will then divide EDX:EAX by whatever operand register you give it. So if you want to divide 1000 / 50, you would do the following: Code: mov eax, 1000 cdq mov ecx, 50 idiv ecx ; quotient is in eax ; remainder is in edx Regarding signed/unsigned integers An unsigned integer is normally 32bits long, and all these bits are used to represent the value of the integer. A signed integer would take away one of these bits, and use it to describe the sign (positive or negative) of the value. That way, only 31bits are left for the value, so the range of a signed integer is twice as small as of its unsigned counterpart. The sign bit (usually the 32nd bit, the most significant bit, the leftmost bit) is 0 if the integer is positive, and 1 if the integer is negative. 

20 Oct 2004, 19:43 

denial
thank you very much for your fast and clear response. Now I understood that.


20 Oct 2004, 20:06 

gorshing
You might also want to read Paul Carter's Tut ... www.drpaulcarter.com ... look at Chapter 2.1
_________________ gorshing 

20 Oct 2004, 20:46 

< Last Thread  Next Thread > 
Forum Rules:

Copyright © 19992020, Tomasz Grysztar. Also on YouTube, Twitter.
Website powered by rwasa.