简体   繁体   中英

Inline assembly with intel syntax using LLVM: Unknown token in expression

When compiling this code with Apple LLVM 4.1 in Xcode I get an error:

#include <stdio.h>

int main(int argc, const char * argv[])
{
    int a = 1;
    printf("a = %d\n", a);

    asm volatile(".intel_syntax noprefix;"
        "mov [%0], 2;"
        :
        : "r" (&a)
        );

    printf("a = %d\n", a);
    return 0;
}

The error is Unknown token in expression .

If I use AT&T syntax it works fine:

asm volatile("movl $0x2, (%0);"
                 :
                 : "r" (&a)
                 : "memory"
                 );

What is wrong with the first code?

It looks like the compiler is translating %0 to %reg ( %rcx on my machine) and the assembler does not like the % (as it is in intel mode).

I don't know if it's possible to mix the automatic register allocation feature ( extended asm ) with the intel syntax, as I've not seen any example yet.

Good documentation about gcc inline assembly is usually hard to come by, and clang states in its documentation that it's mostly compatible with gcc in this area...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM