3.5. Assembler Listings
The compiler normally turns a text based source file into a binary
It is possible however to instruct it to just convert
the source code into assembler and stop there.
The -S option does this.
It also possible to instruct the compiler to produce an
assembler listing as well as an object file.
That can be done as follows:
gcc -c -O2 -Wa,-al hello.c
-c tells GCC to compile or assemble source files, but not to
-O2 produces more fully optimized code.
are both optional.
-Wa tells the compiler to pass the
comma-separated list of options which follows it on to the assembler.
The -al option is an assembler option to request an
This example shows a partial excerpt of an assembler listing for
an x386-based target.
30 0027 90 .p2align 2,,3
31 .globl main
32 .type main,@function
34 0028 55 pushl %ebp
35 0029 89E5 movl %esp, %ebp
36 002b 83EC08 subl $8, %esp
37 002e 83E4F0 andl $-16, %esp
38 0031 83EC0C subl $12, %esp
39 0034 680E0000 pushl $.LC1
40 0039 C7050000 movl $3, a
41 0043 E8FCFFFF call puts
42 0048 C7042404 movl $4, (%esp)
Example 3-2. Assembly listing excerpt
It also possible to produce an
assembler listing that intermixes the original input source code with
the assembler instructions produced by the compiler.
This can help
track down bugs, discover how the compiler handles certain language
constructs (such as function calls) and to learn more about assembly
To do this, just add an h to the assembler option
gcc -c -g -O2 -Wa,-alh hello.c