欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

在 Linux 下通过程序集获取 CPU ID,通过窗口命令获取 CPU ID

最编程 2024-06-27 15:12:17
...
【直播预告】大模型会取代程序员吗?”

#include <stdio.h>
int main(int argc, char * argv[])
{
    
    unsigned int s1 = 0;
    unsigned int s2 = 0;
    asm volatile
    (
        "movl $0x01, %%eax; \n\t"
        "xorl %%edx, %%edx; \n\t"
        "cpuid; \n\t"
        "movl %%edx, %0; \n\t"
        "movl %%eax, %1; \n\t"
        : "=m"(s1), "=m"(s2)
    );

    printf("%08X%08X", htonl(s2), htonl(s1));
    
    return 0;
}
 

----------------------------------------

windows 下获取cpu id命令:

wmic cpu get ProcessorId

---------------------------

arm 获取cpuid


#include <stdio.h>
int main(int argc,char* argv[])
{
        unsigned long  arm_cpuid;
        __asm__("mrs %0, MIDR_EL1" : "=r"(arm_cpuid));
        printf("%016X",htonl(arm_cpuid));
        return 0;
}
 

上一篇: CPUID

下一篇: Linux 查看 CPU 详情

推荐阅读