the difference between two style of inline ASM

42 views Asked by At

My code print FAIL as follow:

Need someone to explain the difference.

I want to know the difference between

__asm__ __volatile__(
    "addl %1,%0;"
    :"=r"(sum)
    :"r"(add1),"r"(add2)
);

and

__asm__ ( "addl %%ebx, %%eax;"
     : "=a" (sum)
     : "a" (add1), "b" (add2) );

My source code:

    int sum = 0;
    int add1 = 100;
    int add2 = 200;

#ifdef __x86_64__
    __asm__ __volatile__(
        "addl %1,%0;"
        :"=r"(sum)
        :"r"(add1),"r"(add2)
    );

    // __asm__ ( "addl %%ebx, %%eax;"
    //     : "=a" (sum)
    //     : "a" (add1), "b" (add2) );

#else
    sum = add1 + add2;
#endif
0

There are 0 answers