Felix Dombek
Felix Dombek

Reputation: 14382

How do I view the compiled machine code or byte code for a C++ function in Visual Studio 2010?

What is the best (quickest) way to view the code that the compiler generated from my files? I'm using mostly C++ but a solution that works for .NET languages would be very welcome as well.

Upvotes: 14

Views: 6094

Answers (3)

In silico
In silico

Reputation: 52197

Within Visual Studio, go to the property pages for your project, then go to C/C++ → Output Files → Assembler Output. It should look something like this:

property page

Note the corresponding compiler switches, all variants of /FA.

  • /FA: Assembly-Only Listing
  • /FAcs: Assembly, Machine Code and Source
  • /FAc: Assembly With Machine Code
  • /FAs: Assembly With Source Code

Underneath the "Assembler Output" option there's an "ASM List Location" option. This is equivalent to the /Fa switch (note capitalization!), and it sets the file path of the output listing.

You can also look at the assembly while debugging (at a breakpoint), complete with the corresponding source code, by right-clicking the current line in the source file text area and clicking "Go To Disassembly".

gotodisassembly

It'll jump to the assembly at the line you right-clicked on in a separate tab. The listing will resemble this:

enter image description here

Yes I know, the screenshots are not from Visual Studio 2010 but the steps and the general appearance are the same. I just don't have immediate access to VS2010 to make screenshots with. :-)

Upvotes: 25

ajay_whiz
ajay_whiz

Reputation: 17951

For .NET you can use the ildasm tool which comes with the framework to view the IL.

Upvotes: 1

James McNellis
James McNellis

Reputation: 355247

For a C++ project, compile with /FA to get an assembly listing.

For .NET assemblies, there's ildasm.

Upvotes: 7

Related Questions