Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easy way to convert c code to x86 assembly?

Tags:

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

like image 453
Bob Avatar asked Apr 25 '10 18:04

Bob


People also ask

Can I convert C to assembly?

Master C and Embedded C Programming- Learn as you go Here we will see how to generate assembly language output from C or C++ source code using gcc. The gcc provides a great feature to get all intermediate outputs from a source code while executing. To get the assembler output we can use the option '-S' for the gcc.

What converts source code to assembly code?

Compilers are a type of translator that support digital devices, primarily computers. The name compiler is primarily used for programs that translate source code from a high-level programming language to a lower level language (e.g., assembly language, object code, or machine code) to create an executable program.

How do you convert assembly language?

Assembly language is converted into executable machine code by a utility program referred to as an assembler; the conversion process is referred to as assembly, or assembling the code.

Does C compile down to assembly?

c is being compiled without any additional links or files, so the program will be converted into an executable by itself. Alas, for the grand finale, let's run the full shebang (no computing reference intended here), gcc main. c without any options, to preprocess, compile, assemble, and link the program all at once.


2 Answers

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

gcc -S input.c -o output.asm -masm=intel
like image 144
SoapBox Avatar answered Sep 18 '22 07:09

SoapBox


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