Wednesday, August 06, 2008

Getting assembly listing embedded with C/C++ Source Code using GCC

I was planning to look at some odd behavior of C++ typedefs and assembly output in the case of GCC/G++ compiler suite for MIPS, especially when O2 optimizations were used.

For most of the compiler suites (Borland, GCC) one can generate the assembly listing by using -S option.

For e.g., if you have file called foo.cpp, then you can see the assembly equivalent by passing -S as an argument to the compiler (Remember that it will not produce the .o / .exe output as usual)
c:\Sriram:\> bcc -S foo.cpp
c:\Sriram:\> mips-elf-gcc.exe -S foo.cpp
This would produce a foo.asm or foo.s output containing the assembly listing in the same folder.

However, I wanted to embed the C/C++ source code for mips-elf-gcc along with the assembly output for easier debug. After looking at many compiler options and googling, I found the mix I need:
c:\Sriram:\> mips-elf-gcc.exe -c -g -Wa,-a,-ad foo.cpp
You might note that I did not include the -S option!

The options are as follows:
-c : Compile only (dont proceed to link - This is because foo.cpp did not have a 'main' or equivalent.
-g :Include debug informaiton
-Wa : Pass the following options (comma seperated to the assembler)
-a : Include high-level, assembly, and symbols listing
-ad : Omit debugging pseudo-ops from the listing

Please look at GCC Documentation and a GNU Assembler Documentation for more information.

1 comment:

Anonymous said...

[url=]generic viagra order cheapest without prescription on line[/url]

Order Viagra Online - only $1.11 per pill.
Learn the cause ofErectile Dysfunction and how to treat ED. Generic cialis mg amp mg, cialis europe cheap viagra , cialis peak blood level,.
[url=]Viagra France[/url]
Cialis, buy cialis, generic cialis, cheapest cialis, cheap cialis, cialis forum, cialis samples , cialis side effects, buy cialis generic , viagra cialislevitra, cialis online discount, no prescription cialis, cialis on line , cialis online , cialis testimonials, cialis experience, cialis free sample ,. 4 Nov 2009 generic cialis viagra caverta buy online cialis free sample no prescription cialis cancdian dugs generic viagra versus cialis pills.
Where can i buy propecia online without a prescription buy propecia drugs buy online without prescription propecia for baldness buy xenical viagra.