简体   繁体   中英

GCC inline assembly

I tried an example from GCC-Inline-Assembly-HOWTO

int main(void)
{
    int foo = 10, bar=15;
    _asm__volatile_( "addl %%ebx,%%eax;\n"
                   :"=a"(foo)
                   :"a"(foo), "b"(bar));
    printf("foo+bar+%d\n",foo);
    return 0;
 }

the above code gives me this error : add_two.c:8:3: error: expected ')' before ':' token .

where have i gone wrong? I am working on ubuntu 12.04 .

_asm__volatile_( "addl %%ebx,%%eax;\n"

...is not correct syntax. asm and volatile are separate keywords.

__asm__ __volatile__( "addl %%ebx,%%eax;\n"

...compiles (and executes with correct result).

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