C语言 将 c 代码转换为 x86 程序集的简单方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2709327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Easy way to convert c code to x86 assembly?
提问by Bob
Is there an easy way (like a free program) that can covert c/c++ code to x86 assembly?
有没有一种简单的方法(如免费程序)可以将 c/c++ 代码转换为 x86 程序集?
I know that any c compiler does something very similar and that I can just compile the c code and then disassemble the complied executable, but that's kind of an overkill, all I want is to convert a few lines of code.
我知道任何 c 编译器都会做一些非常相似的事情,我可以只编译 c 代码,然后反汇编编译后的可执行文件,但这有点矫枉过正,我只想转换几行代码。
Does anyone know of some program that can do that?
有谁知道一些可以做到这一点的程序?
EDIT: I know that GCC compiler does that but it's AT&T syntax and I'm looking for the Intel syntax (not sure if it's called intel syntax or not). The AT&T syntax looks a bit like gibberish to me and some commands use operands in reverse order and not how I'm used to and it can get really confusing.
编辑:我知道 GCC 编译器会这样做,但它是 AT&T 语法,我正在寻找 Intel 语法(不确定它是否称为 intel 语法)。AT&T 语法对我来说有点像胡言乱语,有些命令以相反的顺序使用操作数,而不是我习惯的方式,它会变得非常混乱。
采纳答案by L??o???n???g???p??o???k???e???
Gcc can do it with the -S switch, but it will be disgustingly ugly at&t syntax.
Gcc 可以使用 -S 开关来做到这一点,但它的 at&t 语法将非常丑陋。
回答by SoapBox
GCC can output Intel syntax assembly using the following command line:
GCC 可以使用以下命令行输出 Intel 语法程序集:
gcc -S input.c -o output.asm -masm=intel
回答by James McNellis
gcc will generate assembly if you pass it the -Soption on the command line.
如果您-S在命令行上传递选项,gcc 将生成程序集。
Microsoft Visual C++ will do the same with the /FAsoption.
Microsoft Visual C++ 将对该/FAs选项执行相同操作。
回答by Norman Ramsey
回答by kennytm
Your compiler is already doing that as you've stated, and most likely will have an option to stop before assembling.
正如您所说,您的编译器已经在执行此操作,并且很可能可以选择在组装之前停止。
For GCC, add the -Sflag.
对于 GCC,添加-S标志。
gcc -S x.c
cat x.s
Edit:If your program is pretty short, you could use the online service at https://gcc.godbolt.org/.
编辑:如果您的程序很短,您可以使用https://gcc.godbolt.org/ 上的在线服务。
回答by D.C.
if you are using gcc as a compiler, you can compile with the -S option to produce assembly code. see http://www.delorie.com/djgpp/v2faq/faq8_20.html
如果您使用 gcc 作为编译器,则可以使用 -S 选项进行编译以生成汇编代码。见http://www.delorie.com/djgpp/v2faq/faq8_20.html
回答by BCS
As many people point out most compilers will do that. If you don't like the syntax,a bit of work with awk or sed should be able to translate. Or I'd be surprised if there wasn't a program that did that bit for you already written somewhere.
正如许多人指出的那样,大多数编译器都会这样做。如果您不喜欢语法,使用 awk 或 sed 进行一些工作应该可以翻译。或者如果没有已经在某处为您编写的程序可以为您做那一点,我会感到惊讶。
回答by Vineel Kumar Reddy
In VC++ the following command can be used to list the assembly code.
在 VC++ 中,以下命令可用于列出汇编代码。
cl /FAs a.c
cl /FAs 交流
回答by yoavstr
notice every architecture has its own unique names and even build differently now when you know the stacks involved using asmvolatilewould b the perfect solution
请注意,当您知道使用asm volatile所涉及的堆栈将是完美的解决方案 时,每个架构都有自己独特的名称,甚至现在构建不同

