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:
“The very natural tendency to use terms derived from traditional grammar like verb, noun, adjective, passive voice, in describing languages outside of Indo-European is fraught with grave possibilities of misunderstanding.”
—Benjamin Lee Whorf (18971934)