user146297
user146297

Reputation: 79

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.

Upvotes: 1

Views: 1337

Answers (1)

Joachim Isaksson
Joachim Isaksson

Reputation: 181077

_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).

Upvotes: 4

Related Questions