While writing new code for Windows, I came across _cpuinfo() from the Windows API. Since I mainly deal with the Linux environment (GCC), I want to have access to CPUInfo.
I tried the following:
#include <iostream> int main() { int a, b; for (a = 0; a < 5; a++) { __asm ( "mov %1, %%eax; " // a into eax "cpuid;" "mov %%eax, %0;" // eax into b :"=r"(b) // output :"r"(a) // input :"%eax","%ebx","%ecx","%edx" // clobbered register ); std::cout << "The code " << a << " gives " << b << std::endl; } return 0; }
This is the use of assembly, but I do not want to reinvent the wheel. Is there any other way to implement CPUInfo without assembly?
Compiler Errors:
lewis@lewis-desktop:~/Desktop/prog$ g++ -Wall CPUInfo.cpp CPUInfo.cpp: In function 'int main()': CPUInfo.cpp:10:22: error: expected ')' before ';' token CPUInfo.cpp:10:23: error: expected primary-expression before ')' token CPUInfo.cpp:10:23: error: expected ';' before ')' token CPUInfo.cpp:8:8: warning: unused variable 'b' [-Wunused-variable] CPUInfo.cpp:12:8: error: expected '}' at end of input
c ++ assembly cpu
TheBlueCat Jan 10 '13 at 20:33
source share