Just to give you a taste of the obstacles that lie in your path, here is a simple inline assembler function, in two dialects. First, the Borland C++ Builder version (I think this compiles under MSVC++ too):
int BNASM_AddScalar (DWORD* result, DWORD x)
{
int carry = 0 ;
__asm
{
mov ebx,result
xor eax,eax
mov ecx,x
add [ebx],ecx
adc carry,eax // Return the carry flag
}
return carry ;
}
Now, the g++ version:
int BNASM_AddScalar (DWORD* result, DWORD x)
{
int carry = 0 ;
asm volatile (
" addl %%ecx,(%%edx)
"
" adcl $0,%%eax
" // Return the carry flag
: "+a"(carry) // Output (and input): carry in eax
: "d"(result), "c"(x) // Input: result in edx and x in ecx
) ;
return carry ;
}
As you can see, the differences are major. And there is no way around them. These are from a large integer arithmetic library that I wrote for a 32-bit environment.
As for embedding 64-bit instructions in a 32-bit executable, I think this is forbidden. As I understand it, a 32-bit executable runs in 32-bit mode, any 64-bit instruction just generates a trap.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…