Is there a C compiler to show you a related program in asm?

I am looking for a compiler or a better C IDE that could generate a fully related program, including functions from CRT, in assembler form. Whether there is a? I tried Visual C Express 2008. It has a disassembler, but it is somewhat weird. I mean, for some reason, it shows a lot of "strange" lines of code, such as mov a,#3 about 100 lines .... This is for training purposes. Thanks for the tips.

+4
source share
5 answers

gcc will generate ASM files. If you use gcc -Wa,-adhln -g [source.c] gcc and how the C source lines will be alternated with the generated assembly code.

clang with LLVM will generate high quality ASM files.

Example:

This function is C:

 long Fibonacci(long x) { if (x == 0) return 0; if (x == 1) return 1; return Fibonacci(x - 1) + Fibonacci(x - 2); } 

Becomes this ASM file:

 _Fibonacci: Leh_func_begin1: pushq %rbp Ltmp0: movq %rsp, %rbp Ltmp1: subq $32, %rsp Ltmp2: movq %rdi, -16(%rbp) movq -16(%rbp), %rax cmpq $0, %rax jne LBB1_2 movq $0, -8(%rbp) jmp LBB1_5 LBB1_2: movq -16(%rbp), %rax cmpq $1, %rax jne LBB1_4 movq $1, -8(%rbp) jmp LBB1_5 LBB1_4: movq -16(%rbp), %rax movabsq $1, %rcx subq %rcx, %rax movq %rax, %rdi callq _Fibonacci movq -16(%rbp), %rcx movabsq $2, %rdx subq %rdx, %rcx movq %rcx, %rdi movq %rax, -24(%rbp) callq _Fibonacci movq -24(%rbp), %rcx addq %rax, %rcx movq %rcx, -8(%rbp) LBB1_5: movq -8(%rbp), %rax addq $32, %rsp popq %rbp ret Leh_func_end1: 

When you do this, you want optimizations to be disabled.

It is also possible to alternate the generated ASM code with a higher-level source, for example, the author did HERE .

+4
source

I don’t know if this will help you, but I use IDAPro and OllyDbg and disasm (on linux / unix) to study internal affairs, and I really liked it.

+1
source

Command line options for this, especially in Visual C ++ Express, using the C ++ compiler, this is / Fa

  -OUTPUT FILES- 

/ Fa [file] name collector listing file
/ FA [scu] configure assembly / Fd [file] name .PDB file
/ Fe executable file name / Fm [file] card name file
/ Fo name object file / Fp file name with a precompiled header / Fr [file] name of the source browser file / FR [file] name extended .SBR file / doc [file] process documentation XML comments and, possibly, name .xdc file

Here you will see the output of the assembler, combining the flags of the preprocessor together, you should see all the outputs mixed with the assembler.

  -PREPROCESSOR- 

/ AI add to assembly search path
/ FU forces the assembly / module / C to not remove comments
/ D {= | #} define macro / E preprocess on stdout
/ EP preprocess to stdout, no # line / P preprocess to download
/ Fx merge the entered code into a file / FI name forcibly includes the file
/ U delete predefined macros / u delete all predefined macros
/ I add to the search path / X ignore "standard places"

Most, if not, ALL compilers can do this, the question is which switches to use.

+1
source

A regular compiler has nothing to do with code after it is connected. The compiler can create an assembly for a single file, but to get the results after linking you pretty much need to use a disassembler. As a note by @dgarcia, IDAPro is very good. Since you are apparently working with Windows, you can also use dumpbin /disasm . It is not as good as IDAPro, but it is free.

0
source
 objdump -D <file-name> 
0
source

All Articles