Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

3.5. Assembler Listings

The compiler normally turns a text based source file into a binary object file. 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 link them. -O2 produces more fully optimized code. These 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 assembler listing.

This example shows a partial excerpt of an assembler listing for an x386-based target.

  29                            .text
  30 0027 90                    .p2align 2,,3
  31                    .globl main
  32                            .type   main,@function
  33                    main:
  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
  39      00
  40 0039 C7050000              movl    $3, a
  40      00000300
  40      0000
  41 0043 E8FCFFFF              call    puts
  41      FF
  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 language. To do this, just add an h to the assembler option like this:

gcc -c -g -O2 -Wa,-alh hello.c

 
 
  Published under the terms of the GNU General Public License Design by Interspire