Division and modulus using single divl instruction (i386, amd64)
I was trying to come up with inline assembly for gcc to get both division and modulus using single divl instruction. Unfortunately, I am not that good at assembly. Could someone please help me on this? Thank you. Yes -- a divl will produce the quotient in eax and the remainder in edx. Using Intel syntax, for example: mov eax, 17 mov ebx, 3 xor edx, edx div ebx ; eax = 5 ; edx = 2 You're looking for something like this: __asm__("divl %2\n" : "=d" (remainder), "=a" (quotient) : "g" (modulus), "d" (high), "a" (low)); Although I agree with the other commenters that usually GCC will do this for you