我看过关于同样错误的帖子,但我仍然收到错误:
too many memory references for `mov'
junk `hCPUIDmov buffer' after expression
...这是代码(mingw编译器/ C::B):
#include iostream
using namespace std;
union aregister
{
int theint;
unsigned bits[32];
};
union tonibbles
{
int integer;
short parts[2];
};
void GetSerial()
{
int part1,part2,part3;
aregister issupported;
int buffer;
__asm(
"mov %eax, 01h"
"CPUID"
"mov buffer, edx"
);//do the cpuid, move the edx (feature set register) to "buffer"
issupported.theint = buffer;
if(issupported.bits[18])//it is supported
{
__asm(
"mov part1, eax"
"mov %eax, 03h"
"CPUID"
);//move the first part into "part1" and call cpuid with the next subfunction to get
//the next 64 bits
__asm(
"mov part2, edx"
"mov part3, ecx"
);//now we have all the 96 bits of the serial number
tonibbles serial[3];//to split it up into two nibbles
serial[0].integer = part1;//first part
serial[1].integer = part2;//second
serial[2].integer = part3;//third
}
}