Easy way to convert c code to x86 assembly?
Is there an easy way (like a free program) that can covert c/c++ code to x86 assembly?
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.
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开发者_如何学JAVA 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 can output Intel syntax assembly using the following command line:
gcc -S input.c -o output.asm -masm=intel
Gcc can do it with the -S switch, but it will be disgustingly ugly at&t syntax.
gcc will generate assembly if you pass it the -S
option on the command line.
Microsoft Visual C++ will do the same with the /FAs
option.
The lcc
compiler is a multiplatform cross-compiler. You can get it to produce Intel syntax assembly code by
lcc -S -Wf-target=x86/win32 foo.c
I find assembly code from lcc
significantly easier to read than what gcc
spits out nowawadays.
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 x.c
cat x.s
Edit: If your program is pretty short, you could use the online service at https://gcc.godbolt.org/.
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
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.
In VC++ the following command can be used to list the assembly code.
cl /FAs a.c
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
精彩评论