见如下代码,经过验证,是可行的。
static const char* cpuId(void)
{
unsigned long s1 = 0;
unsigned long s2 = 0;
unsigned long s3 = 0;
unsigned long s4 = 0;
__asm
{
mov eax,00h
xor edx,edx
cpuid
mov s1, edx
mov s2, eax
}
__asm
{
mov eax,01h
xor ecx,ecx
xor edx,edx
cpuid
mov s3, edx
mov s4, ecx
}
static char buf[100];
sprintf(buf, "%08X%08X%08X%08X", s1, s2, s3, s4);
return buf;
}