将c代码转换成x86程序集的简单方法?

时间:2021-09-19 03:15:25

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的语法在我看来有点像胡言乱语,有些命令使用操作数的顺序是颠倒的,而不是我习惯的方式,这会让人感到非常困惑。

9 个解决方案

#1


12  

Gcc can do it with the -S switch, but it will be disgustingly ugly at&t syntax.

Gcc可以用-S开关来做,但是它会令人厌恶地讨厌at&t的语法。

#2


43  

GCC can output Intel syntax assembly using the following command line:

GCC可以使用以下命令行输出Intel语法汇编:

gcc -S input.c -o output.asm -masm=intel

#3


13  

gcc will generate assembly if you pass it the -S option on the command line.

如果在命令行中传递-S选项,gcc将生成程序集。

Microsoft Visual C++ will do the same with the /FAs option.

Microsoft Visual c++也会使用/FAs选项。

#4


7  

The lcc compiler is a multiplatform cross-compiler. You can get it to produce Intel syntax assembly code by

lcc编译器是一个跨平台的编译器。您可以通过它生成Intel语法汇编代码

lcc -S -Wf-target=x86/win32 foo.c

I find assembly code from lcc significantly easier to read than what gcc spits out nowawadays.

我发现lcc的汇编代码比gcc现在发布的代码要容易得多。

#5


3  

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 -S flag.

对于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/上使用在线服务。

#6


1  

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

#7


0  

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进行一些工作应该能够进行翻译。或者,如果没有一个程序为你写了这样的代码,我将会很惊讶。

#8


0  

In VC++ the following command can be used to list the assembly code.

在vc++中,可以使用以下命令列出汇编代码。

cl /FAs a.c

cl / FAs交流

#9


0  

notice every architecture has its own unique names and even build differently now when you know the stacks involved using asm volatile would b the perfect solution

请注意,每个体系结构都有自己独特的名称,如果您知道使用asm volatile的栈将是一个完美的解决方案,那么现在甚至可以构建不同的体系结构

#1


12  

Gcc can do it with the -S switch, but it will be disgustingly ugly at&t syntax.

Gcc可以用-S开关来做,但是它会令人厌恶地讨厌at&t的语法。

#2


43  

GCC can output Intel syntax assembly using the following command line:

GCC可以使用以下命令行输出Intel语法汇编:

gcc -S input.c -o output.asm -masm=intel

#3


13  

gcc will generate assembly if you pass it the -S option on the command line.

如果在命令行中传递-S选项,gcc将生成程序集。

Microsoft Visual C++ will do the same with the /FAs option.

Microsoft Visual c++也会使用/FAs选项。

#4


7  

The lcc compiler is a multiplatform cross-compiler. You can get it to produce Intel syntax assembly code by

lcc编译器是一个跨平台的编译器。您可以通过它生成Intel语法汇编代码

lcc -S -Wf-target=x86/win32 foo.c

I find assembly code from lcc significantly easier to read than what gcc spits out nowawadays.

我发现lcc的汇编代码比gcc现在发布的代码要容易得多。

#5


3  

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 -S flag.

对于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/上使用在线服务。

#6


1  

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

#7


0  

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进行一些工作应该能够进行翻译。或者,如果没有一个程序为你写了这样的代码,我将会很惊讶。

#8


0  

In VC++ the following command can be used to list the assembly code.

在vc++中,可以使用以下命令列出汇编代码。

cl /FAs a.c

cl / FAs交流

#9


0  

notice every architecture has its own unique names and even build differently now when you know the stacks involved using asm volatile would b the perfect solution

请注意,每个体系结构都有自己独特的名称,如果您知道使用asm volatile的栈将是一个完美的解决方案,那么现在甚至可以构建不同的体系结构