Accessing The Id From Other Languages
This information is easy to access from other languages as well. For instance, the C++ code for gcc below prints the first five values, returned by the cpuid:
#includeIn C, the code may be shortened to:
int main { int a, b; for (a = 0; a < 5; a++) { __asm( "cpuid" : "=a" (b) // EAX into b (output) : "a" (a) // a into EAX (input) :"%ebx","%ecx","%edx"); // cpuid always clobbers these printf("The code %i gives %i\n", a, b); } return 0; }Or, a generally useful C implementation that works on 32 and 64 bit setups:
#includeMicrosoft Visual C compiler has builtin function __cpuid so cpuid instruction may be embedded without using inline assembly. This is handy since x64 version of MSVC doesn't allow inline assembly at all. The same program for MSVC would be:
#includeFor Borland/Embarcadero C compilers (bcc32), native asm function calls are necessary, as there is no asm implementation. The pseudo code:
unsigned int a, b, c, d; unsigned int InfoType = 0; __asm xor EBX, EBX; __asm xor ECX, ECX; __asm xor EDX, EDX; __asm mov EAX, InfoType; __asm cpuid; __asm mov a, EAX; __asm mov b, EBX; __asm mov c, ECX; __asm mov d, EDX;Read more about this topic: CPUID
Famous quotes containing the word languages:
“I am always sorry when any language is lost, because languages are the pedigree of nations.”
—Samuel Johnson (17091784)