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

♀尐吖头ヾ 提交于 2019-11-27 20:40:10

问题


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?


回答1:


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.




回答2:


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).




回答3:


You could also run that program in a debugger like gdb and use a disassembly view. In gdb you could use the command disass/m to view the assembly mixed with the C code on the current location.




回答4:


You could stop you program at a breakpoint in the Visual Studio debugger and do "show assembly" and even step through it one instruction at a time.



来源:https://stackoverflow.com/questions/1354899/how-can-i-see-the-assembly-code-that-is-generated-by-a-gcc-any-flavor-compiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!