Jar*_*sen 2 c cpu gcc inline-assembly detection
我需要找到CPU的架构类型.我没有访问/ proc/cpuinfo,因为机器正在运行syslinux.我知道有一种方法可以使用内联ASM,但我相信我的语法不正确,因为我的变量iedx没有正确设置.
我和ASM一起苦苦挣扎,绝不是专家.如果有人有任何提示或能指出我正确的方向,我会非常感激.
static int is64Bit(void) {
int iedx = 0;
asm("mov %eax, 0x80000001");
asm("cpuid");
asm("mov %0, %%eax" : : "a" (iedx));
if ((iedx) && (1 << 29))
{
return 1;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
你可以在如此少的行中容纳多少个错误;)
尝试
static int is64bit(void) {
int iedx = 0;
asm volatile ("movl $0x80000001, %%eax\n"
"cpuid\n"
: "=d"(iedx)
: /* No Inputs */
: "eax", "ebx", "ecx"
);
if(iedx & (1 << 29))
{
return 1;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
682 次 |
最近记录: |