I trying to convert function "__cpuid" from С language to C++. I have a problem that the g++ compiler does not work with Intel assembler.
I'm trying to translate this code:
__asm
{
mov esi, CPUInfo
mov eax, InfoType
xor ecx, ecx
cpuid
mov dword ptr[esi + 0], eax
mov dword ptr[esi + 4], ebx
mov dword ptr[esi + 8], ecx
mov dword ptr[esi + 12], edx
}
I tried to do it using examples from the Internet, I got this code, but it doesn't work:
__asm
(
"movl %CPUInfo,%esi\n"
"movl %InfoType,%eax\n"
"xorl %ecx,%ecx\n"
"cpuid\n"
"movl %eax,0(%esi)\n"
"movl %ebx,4(%esi))\n"
"movl %ecx,8(%esi)\n"
"movl %edx,12(%esi)\n"
:"=r"(CPUInfo)
);
On linux (and in many other platforms, non-linux, non-gcc), you can assemble the intel assembly code into an object file with assembler such as
nasm. Then you can link your assembly object into the application without need of mixing messages or assembly language syntax.