Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 676
Felix Dombek Avatar asked Aug 25 '11 04:08

Felix Dombek


People also ask

How do I find the assembly code of C program in Visual Studio?

You can normally see assembly code while debugging C++ in visual studio (and eclipse too). For this in Visual Studio put a breakpoint on code in question and when debugger hits it rigth click and find "Go To Assembly" ( or press CTRL+ALT+D )

Is C compiled to bytecode?

Microsoft's C compiler has been able to compile to bytecode for decades. The UCSD Pascal compiler has done so for even longer!

What is byte code in compiler design?

Bytecode is computer object code that an interpreter converts into binary machine code so it can be read by a computer's hardware processor. The interpreter is typically implemented as a virtual machine (VM) that translates the bytecode for the target platform.

Is byte code assembly code?

Bytecode is something like an assembly language. It's not a real assembly language. The Java Virtual Machine then "runs" this fake assembly language, effectively translating it to a real assembly language.


2 Answers

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. :-)

like image 174
In silico Avatar answered Sep 22 '22 05:09

In silico


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

For .NET assemblies, there's ildasm.

like image 38
James McNellis Avatar answered Sep 21 '22 05:09

James McNellis