Warm tip: This article is reproduced from serverfault.com, please click

How can I compile to assembly with gcc

发布于 2011-11-05 17:24:09

How do I compile to assembly instead of an executable with gcc. I know there is an -S flag, but where do I use it in the makefile. For example, if I use flags -O3 -o exe_name, where should I put the -S flag?

Questioner
MetallicPriest
Viewed
0
Basile Starynkevitch 2018-07-04 21:08:02

I suggest also using -fverbose-asm because then the generated assembler has some generated comments which "explains" the code. For example:

gcc -S -fverbose-asm -O2 foo.c

would generate in foo.s (with some comments) the assembler code produced by compiling foo.c

And to understand what the GCC optimizations are doing one could even try -fdump-tree-all (but this produces hundreds of files!).