An assembly language is a low-level programming language designed for a specific type of processor. It may be produced by compiling source code from a high-level programming language (such as C/C++) but can also be written from scratch. Assembly code can be converted to machine code using an assembler.
We can write assembly program code inside c language program. In such case, all the assembly code must be placed inside asm{} block.
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 )
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
.
If you have a compiled binary,
objdump -d a.out
on UNIX (also works for cygwin),dumpbin /DISASM foo.exe
on Windows.Debuggers could also show disassembly.
disas
command in GDB.set disassembly-flavor intel
if you prefer Intel syntax.In GCC/G++, compile with -S
. That will output a something.s
file with the assembly code.
Edit: If you want the output to be in Intel syntax (which is IMO, much more readable, and most assembly tutorials use it), compile with -masm=intel
.
In Visual Studio;
For gcc/g++
gcc -save-temps -fverbose-asm prog.c
This will generate prog.s with some comments on variables used in every asm line:
movl $42, -24(%ebp) #, readme
movl -16(%ebp), %eax # pid, pid
movl %eax, 4(%esp) # pid,
movl $.LC0, (%esp) #,
call printf #
This site is currently working for me (2017): https://godbolt.org/
Lots of people already told how to emit assembly code with a given compiler. Another solution is to compile an object file and dump it with a tool such objdump, readelf (on Unix) or DUMPBIN(link) (on Windows). You can also dump an executable, but it will be more difficult to read the output.
This has the advantage of working the same way with any compiler.
Whatever debugger you're using should have an assembly view (Visual Studio, Borland IDE, gdb, etc.). If you are not using a debugger and you merely want to see what assembly is in a program, you can use a disassembler or alternatively, run the program and attach to it with a debugger and do the dump from there. See references to disassemblers for information on options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With