How do I compile the asm generated by GCC?

前端 未结 7 2006
南方客
南方客 2020-12-04 06:18

I\'m playing around with some asm code, and something is bothering me.

I compile this:

#include 

int main(int argc, char** argv){
  p         


        
7条回答
  •  情深已故
    2020-12-04 06:50

    You can embed the assembly code in a normal C program. Here's a good introduction. Using the appropriate syntax, you can also tell GCC you want to interact with variables declared in C. The program below instructs gcc that:

    • eax shall be foo
    • ebx shall be bar
    • the value in eax shall be stored in foo after the assembly code executed

    \n

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

提交回复
热议问题