c++ - C/C++ 代码的等效 asm 代码

标签 c++ c assembly ubuntu

<分区>

Possible Duplicate:
How do you get assembler output from C/C++ source in gcc?

你好!

我有一个 C 和 C++ 源代码,我想在汇编代码中查看。我怎样才能为那些生成等效的 asm 代码?我应该使用什么工具?或者是否已经可以使用 gcc 编译器等工具?那我应该执行什么命令呢?我更喜欢 Linux 之上的工具,尤其是 Ubuntu。

提前致谢!

最佳答案

gcc -S x.c

这应该会生成 gcc 认为与您的代码等效的程序集。但是请注意,优化器可以做一些非常棘手的事情,这些事情可能很难看出它们在功能上等同于您的代码。特别是在 c++ 中,优化器非常依赖内联和类似的东西。

来自 gcc 手册页:

-S

Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler code file for each non-assembler input file specified. By default, the assembler file name for a source file is made by replacing the suffix .c, .i, etc., with .s.

Input files that don't require compilation are ignored.

关于c++ - C/C++ 代码的等效 asm 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3155377/

相关文章:

java - 验证错误: Stack size too large (what does it mean?)

c++ - 在构造函数中将类成员函数分配给映射

c++ - memset() 函数输出不理想

c - 数据结构的建议!

c - 多线程场景下线程退出差异

c - x86 addl 与 subl

c - 使用 GCC 中的 4 位 PowerPC CR0 寄存器

c++ - 没有for循环的集合中n个连续项的总和

c++ - 了解 Node.js 的 napi_value 类型的定义

c - 如何减少 NCurses C 应用程序中的输入延迟