How can I see the assembly code for a C++ program?

By : Geek
Source: Stackoverflow.com
Question!

How can I see the assembly code for a C++ program?

What are the popular tools to do this?

By : Geek


Answers

You can also try this site: http://assembly.ynh.io/

There, you can paste your C or C++ code and press a blue button to see the assembly equivalent version.



Ask the compiler

If you are building the program yourself, you can ask your compiler to emit assembly source. For most UNIX compilers use the -S switch.

  • If you are using the GNU assembler, compiling with -g -Wa,-alh will give intermixed source and assembly on stdout (-Wa asks compiler driver to pass options to assembler, -al turns on assembly listing, and -ah adds "high-level source" listing):

    g++ -g -c -Wa,-alh foo.cc

  • For Visual Studio, use /FAsc.

Peek into the binary

If you have compiled binary,

Use your debugger

Debuggers could also show disassebly.



If you're an Eclipse user, you can use the Disassembly view.

The Disassembly view shows the loaded program as assembler instructions mixed with source code for comparison. The currently executing line is indicated by an arrow marker and highlighted in the view. You can do the following tasks in the Disassembly view:

  • Set breakpoints at the start of any assembler instruction
  • Enable and disable breakpoints and their set their properties
  • Step through the disassembly instructions of your program
  • Jump to specific instructions in the program
By : Pieter


This video can help you solving your question :)
By: admin