Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see the assembly code that is generated by a gcc (any flavor) compiler for a C/C++ program?

I am trying to optimize a lot of multiplications and pointer arithmetics and would like to see what the compiler does underneath when I put in optimization flags.

--Edit--

How to restrict it to a specific function or a code block?

--Edit_2--

How to let gcc generate a less verbose assembly-code?

like image 827
vehomzzz Avatar asked Aug 30 '09 21:08

vehomzzz


People also ask

How do I find my assembly code?

Go to project properties, then to C++/Output Files and set Assembler Output setting and ASM list location to a file name. Show activity on this post. You have to provide the compiled object code as a parameter. Show activity on this post.

How do I find the assembly code for AC program in Linux?

With gcc or g++ compiler, you can use the -S flag to see the assembly code generated.

Does gcc compile to assembly or machine code?

GCC compiles to assembler. Some other compilers don't. For example, LLVM-GCC compiles to LLVM-assembly or LLVM-bytecode, which is then compiled to machine code. Almost all compilers have some sort of internal representation, LLVM-GCC use LLVM, and, IIRC, GCC uses something called GIMPLE.

How do I find my assembly code in Vscode?

If you are talking about debugging to see the assembly code, the easiest way is Debug->Windows->Disassembly (or Alt-8). This will let you step into a called function and stay in Disassembly.


2 Answers

Add -S switch to your command line.

Edit: Do not forget that it will place the assembly to the files you specified under -o switch.

like image 51
P Shved Avatar answered Sep 17 '22 16:09

P Shved


How to restrict it to a specific function or a code block?

Put that function in a separate source file (and use a different command-line parameter for that one source file).

like image 35
ChrisW Avatar answered Sep 17 '22 16:09

ChrisW