[英]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-- --Edit_2--
How to let gcc generate a less verbose assembly-code? 如何让gcc生成一个不那么详细的汇编代码?
Add -S
switch to your command line. 将
-S
开关添加到命令行。
Edit: Do not forget that it will place the assembly to the files you specified under -o
switch. 编辑:不要忘记它会将程序集放在您指定的
-o
开关下的文件中。
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). 将该函数放在单独的源文件中(并为该源文件使用不同的命令行参数)。
You could also run that program in a debugger like gdb
and use a disassembly view. 您也可以在像
gdb
这样的调试器中运行该程序并使用反汇编视图。 In gdb
you could use the command disass/m
to view the assembly mixed with the C code on the current location. 在
gdb
您可以使用命令disass/m
来查看与当前位置上的C代码混合的程序集。
您可以停止在Visual Studio调试器中的断点处编程并执行“显示汇编”,甚至一次一步地执行它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.