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