Code Gem

Code Gem

Knowledge was arriving in dribs and drabs

Code Gem RSS Feed
 
 
 
 

Generate Assembly From C++ Code in Visual Studio

Sometimes we want to see the assembly code generated from a piece of C++ code. It could be very helpful for:

  • Better understanding about how compiler optimize our code
  • Better understanding about the dark side of the programming language that we are using to avoid the pitfalls.
  • Finding performance hints.
  • Debugging really tricky defects.

And I found that I am not the only person have this wish:

Larry’s Rule of Software Engineering, Part I: Every software engineer should know roughly what assembly language their code generates.

So I think the only question left is: how to generate assembly from our C++ source code? You can of course use a debugger to disassembly the binary file but apparently that is not an efficient way.

There is actually an option in Visual C++. Right click the cpp file and select ‘Properties’. In the property pages set Configuration Properties –> C/C++ –> Output Files –> Assembler Output to “Assembly With Source Code (/FAs)”:

C  _Assembly_Options After build your project you should be able to find the *.asm file generated under $(IntDir), as set in “ASM List Location” property.

You can make the similar change in your project property page. I would not recommend to do this as that will generate assembly for all cpp files in your project, which is not necessary in most cases, and will greatly slow down your compile speed.

Internally change the property just enable the /FAs switch for cl.exe. You can take a look at MSDN for more detailed information.

Share/Save/Bookmark

2 Responses to “Generate Assembly From C++ Code in Visual Studio”

  1. 1
    What did we pay for C++ Runtime Polymorphism: Part I | Code Gem:

    [...]         « Generate Assembly From C++ Code in Visual Studio [...]

  2. 2
    Big bonus:

    Good morning
    I loose control!
    Free java casino no download
    casino
    List flash no download casino
    casino
    Virtual casino birthday welcome bonus
    casino
    Flash no download casino without deposit
    casino
    Internet poker web sites

Leave a Reply

September 2010
M T W T F S S
« Feb «-»  
 12345
6789101112
13141516171819
20212223242526
27282930  

Blogroll