Displaying assembly at Visual Studio

3.4k views Asked by At

Is it possible to see an assembly of C/C++ code at Microsoft Visual Studio? Can I ask to see specific assembly type (MIPS assembly)?

1

There are 1 answers

0
Cody Gray - on strike On

Is it possible to see an assembly of C/C++ code at Microsoft Visual Studio?

Yes, it is. There are three basic ways:

  1. Ask the compiler to emit an assembly listing for each translation unit during the compilation process.

    This is done using the /FA switch, which has a variety of options available to customize the type of listing that is generated.

    You can configure this in the IDE by right-clicking on the project in the Solution Explorer and opening the project settings. Then, you'll find the various options listed under C/C++ → Output Files → Assembly Output.

    Make sure that you enable this option for the appropriate project settings; namely, for "Debug" or "Release" mode! Although you can configure it for either or both, my advice would be to enable it only for "Release" mode since looking at unoptimized debugging-mode assembly code is an uninteresting waste of time.

  2. Display the actual assembly code for the binary that is currently being debugged.

    Run the compiled application under the debugger and then break into it (either by hitting a defined breakpoint or arbitrary pressing the "Break" button on the toolbar; you could even single-step into the program using the debugger). Once execution is broken, right-click in the editor and choose "Go To Assembly). Using the keyboard, this is either Ctrl+Alt+D, or Alt+8.

    I keep the "Disassembly" window docked as one of my main code tabs so it is always there and I can switch to it on-demand. Although this window can only be displayed in debug mode, Visual Studio supports this well, since it maintains separate "design" and "debug" mode window layouts.

    (Note that this doesn't work for static libraries, since they cannot be executed until they are linked into an executable. For those, you will need to use approach #1.)

  3. Statically disassemble your binary.

    Open the Visual Studio Command Prompt (so that your environment variables are set up correctly), and then use link.exe's /disasm option. For example:

    link.exe /disasm /dump /linenumbers /out:MyApp.asm MyApp.exe
    

Can I ask to see specific assembly type (MIPS assembly)?

No. You will only see the assembly code for the processor that you are actually targeting when you compile. Modern versions of Visual Studio support only x86-32 (also known as x86 or IA-32), x86-64 (also known as x64 or AMD64), and ARM. Historically, there were also Alpha, PowerPC, and probably MIPS versions of the compiler. If you have one of these, and can generate MIPS binaries, then it will support the necessary options.

If you don't have an MIPS compiler, then there is obviously not going to be any way to see MIPS assembly code! An x86 compiler doesn't generate MIPS assembly!