本来想写一个单独的一个cpuinfo函数来获得CPU的品牌,结果按AT&T格式写完一编译,出错了,然后上网搜索答案,原来ELF和PE的代码结构还是不一样滴,建议内嵌汇编代码,这样比较通用。于是乎,下面的代码就出来了。
1
#include
<
stdio.h
>
2
3 int main()
4 {
5 char spValue [ 13 ] = { 0 };
6
7 asm( " movl $0, %%eax\n\t "
8 " cpuid\n\t "
9 " movl %%ebx, (%0)\n\t "
10 " movl %%edx, 4(%0)\n\t "
11 " movl %%ecx, 8(%0)\n\t "
12 :
13 : " D " (spValue)
14 : " eax " , " ebx " , " ecx " , " edx "
15 );
16 printf( " The CPUID is: %s \n " , spValue);
17 getchar();
18 return 0 ;
19 }
2
3 int main()
4 {
5 char spValue [ 13 ] = { 0 };
6
7 asm( " movl $0, %%eax\n\t "
8 " cpuid\n\t "
9 " movl %%ebx, (%0)\n\t "
10 " movl %%edx, 4(%0)\n\t "
11 " movl %%ecx, 8(%0)\n\t "
12 :
13 : " D " (spValue)
14 : " eax " , " ebx " , " ecx " , " edx "
15 );
16 printf( " The CPUID is: %s \n " , spValue);
17 getchar();
18 return 0 ;
19 }