网上搜的,不知道对不对
#include <stdio.h>
// dividend, divisor, quotient and remainder should be replaced with variables instead of constant number
#define GET_DIV_AND_MOD(dividend, divisor, quotient, remainder) \
__asm{ \
__asm push eax \
__asm push edx \
__asm mov eax, dword ptr[dividend] \
__asm cdq \
__asm idiv dword ptr[divisor] \
__asm mov dword ptr[quotient], eax \
__asm mov dword ptr[remainder], edx \
__asm pop edx \
__asm pop eax \
}
void main(void)
{
int a = 9, b = 4;
int quo=0, rem=0;
//GET_DIV_AND_MOD(a, b, quo, rem);
quo = a / b;
GET_DIV_AND_MOD(a, b, quo, rem);
printf("The quo is: %d, and the rem is: %d\n", quo, rem);
}
|