Reputation: 183
I tried to read CPUID using assembler in C++. I know there is function for it in , but I want the asm way. So, after CPUID is executed, it should fill eax,ebx,ecx registers with ASCII coded string. But my problem is, since I can in asm adress only full, or half eax register, how to break that 32 bits into 4 bytes. I used this:
#include <iostream>
#include <stdlib.h>
int main()
{
_asm
{
cpuid
/*There I need to mov values from eax,ebx and ecx to some propriate variables*/
}
system("PAUSE");
return(0);
}
Upvotes: 2
Views: 791
Reputation: 68972
I don't understand why you don't use the provided function anyway
Either link real assembly code the way real man go ;-)
Or use the common way
Upvotes: 0
Reputation: 6081
The Linux kernel source shows how to execute x86 cpuid using inline assembly. The syntax is GCC specific; if you're on Windows this probably isn't helpful.
static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
unsigned int *ecx, unsigned int *edx)
{
/* ecx is often an input as well as an output. */
asm volatile("cpuid"
: "=a" (*eax),
"=b" (*ebx),
"=c" (*ecx),
"=d" (*edx)
: "0" (*eax), "2" (*ecx));
}
Once you have a function in this format (note that EAX, ECX are inputs, while all four are outputs), you can easily break out the individual bits/bytes in the caller.
Upvotes: 2