views:

374

answers:

1

hi there, for the sake of simplicity ill just paste an example instead of my entire code which is a bit huge. while im porting my code to VC++ instead of using GCC i need to rewrite a few inline assembly functions that receive pointers and save values on those pointers.

imagine cpuid for example:

void cpuid( int* peax, int* pebx, int* pecx, int* pedx, int what ){
    __asm__ __volatile__( "cpuid" : "=a" (*peax), "=b" (*pebx), "=c" (*pecx), "=d" (*pedx) : "a" (what) );
}

that will just work, it will save the values on the registers "returned" by cpuid on the pointers that i passed to the function.

can the same be done with the inline assembler for VC? so far the exact same function signature but with:

mov eax, what;
cpuid;
mov dword ptr [peax], eax;
etc

wont work, peax will have the same value it had before calling the function.

thanks in advance.

+1  A: 

Tough to see because it is just a snippet, plus it could be called from C++ code / thiscall.

It might have to be 'naked' ( __declspec(naked) ) in some cases.

It won't port as VC is dropping x64 inline asm support iirc.

Use the __cpuid or __cpuidex intrinsic and enjoy.

rama-jka toti