AT& T内联语法

时间:2009-12-18 19:02:05

标签: gcc assembly x86 inline-assembly att

任何人都可以使用正确的AT& T语法来完成我在INTEL中正在做的事情 我已经展示了我在AT& T的尝试,但他们没有编译......

unsigned int CheckIfGenuineIntel(void)
{
    unsigned int VendorIdentificationString[4] = {0, 0, 0, 0};

#if defined( _DO_INTEL_ )
    __asm__ __volatile__
    (
        "xor eax, eax\n\t"
        "cpuid\n\t"
        "mov %0, ebx\n\t"
        "mov %0 + 4, edx\n\t"
        "mov %0 + 8, ecx"
        :"=m"(VendorIdentificationString)
        :
        :"eax", "ebx", "ecx", "edx"
    );
#else
    asm volatile
    (
        "xor %%eax, %%eax\n\t"
        "cpuid\n\t"
        "movl %%ebx, %0\n\t"
        "movl %%edx, 4(%0)\n\t"
        "movl %%ecx, $8(%0)"
        :"=m"(VendorIdentificationString)
        :
        :"eax", "ebx", "ecx", "edx"
    );
#endif

    printf("\nCheckIfGenuineIntel:  '%s'\n", (char *)&VendorIdentificationString[0]);
    return 1;
}

2 个答案:

答案 0 :(得分:1)

这些行:

"movl %%edx, 4(%0)\n\t"
"movl %%ecx, $8(%0)"

应该是:

"movl %%edx, 4+%0\n\t"
"movl %%ecx, 8+%0"

这似乎让gcc 3.4.4很开心。

答案 1 :(得分:0)

查看intel2gas,这是一种从英特尔语法转换为AT& T语法的工具。