问问题
1841 次
2 回答
3
Rule of thumb is, if you ever write a mov
in inline asm you are probably doing it wrong :)
The compiler can load/store values for you on its own, ie.
int dummy;
union {
char text[12];
struct {
int ebx;
int edx;
int ecx;
};
} vendorname;
__asm__(
"cpuid \n"
: "=b" (vendorname.ebx), "=d" (vendorname.edx), "=c" (vendorname.ecx), "=a" (dummy)
: "a" (0)
);
Note that the case was complicated by having to interpret the 3 dwords as a string.
于 2013-10-16T19:44:38.477 回答
1
You can do it as:
#include <stdio.h>
int main(int argc, char **argv) {
static char vendername[50] = {0};
__asm__ __volatile__ (
"movl $0, %%eax\n"
"cpuid\n"
"movl %%ebx, %0\n"
"movl %%edx, %0 + 4\n"
"movl %%ecx, %0 + 8\n"
:"=m"(vendername)
:
:"eax", "ebx", "edx", "ecx"
);
printf("%s\n", vendername);
return 0;
}
于 2013-10-16T20:14:27.233 回答