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,-alhwill give intermixed source and assembly on stdout (-Waasks compiler driver to pass options to assembler,-alturns on assembly listing, and-ahadds “high-level source” listing):g++ -g -c -Wa,-alh foo.cc -
For Visual Studio, use
/FAsc.
Peek into a binary
If you have a compiled binary,
- use
objdump -d a.outon UNIX (also works for cygwin), dumpbin /DISASM foo.exeon Windows.
Use your debugger
Debuggers could also show disassembly.
- Use
disascommand in GDB.
Useset disassembly-flavor intelif you prefer Intel syntax. - or the disassembly window of Visual Studio on Windows.