Im not quite sure yet how division works in x86 assembly (GAS AT&T syntax). What i wanna do is to divide two longs, and then multiply the quotient with the divisor to see if the new number is equal to the initial number (n/m * m = n).
movl %ebx, %eax
movl %ecx, %edx
idivl %edx
imull %ebx, %edx
cmp %edx, %ebx
je .equal
The code above is a snippet where i do the division. ebx and ecx are two counters that i want to divide, is it correct that the eax register is used as divisor? so when i write idivl %edx i am dividing edx with eax, and i get the integer closest 0? Like 7/2 = 3? I read one place that the quotient is stored in the edx register and the remainder in the ah register, but i was also told that the quotient is stored in the eax register and the remainder in the edx register, which has gotten me confused.
Though the main question here is: i want to divide the value of the ebx register with the value of the ecx register, how should i proceed?
Thanks!
EDIT: the code above yields an floating point exception
n/m*m == n
then justn % m == 0
is enough – phuclv%edx:%eax
(a 64 bit value), divisor is the operand (using%edx
seems like a bad idea since it constitutes part of the dividend), quotient goes to%eax
and remainder to%edx
. – davmac