Using GCC to produce readable assembly?

后端 未结 10 2116
死守一世寂寞
死守一世寂寞 2020-11-22 06:13

I was wondering how to use GCC on my C source file to dump a mnemonic version of the machine code so I could see what my code was being compiled into. You can do this with J

10条回答
  •  我寻月下人不归
    2020-11-22 06:48

    godbolt is a very useful tool, they list only has C++ compilers but you can use -x c flag in order to get it treat the code as C. It will then generate an assembly listing for your code side by side and you can use the Colourise option to generate colored bars to visually indicate which source code maps to the generated assembly. For example the following code:

    #include 
    
    void func()
    {
      printf( "hello world\n" ) ;
    }
    

    using the following command line:

    -x c -std=c99 -O3
    

    and Colourise would generate the following:

    enter image description here

提交回复
热议问题