Wednesday, November 25, 2009

GCC Compile C into asm, hving the corresponding C code next to the asm, possible?

GCC Compile C into asm, hving the corresponding C code next to the asm, possible?

Is there a parameter in GCC that allow you to compile
C into assembly, whilst also having the corresponding C
code next to the generated assembly?

For example:
ubuntubox> gcc -S -?? helloworld.c

ubuntubox> cat helloworld.s
....
.globl main
.type main,@function
main:
pushl %ebp
movl %esp,%ebp
pushl $.LC0
call printf /* printf("Hello, world!\n"); */
addl $4,%esp
xorl %eax,%eax
jmp .L1
leave /*return 0;*/
ret

Something like that??


Many Thanks,

Andrea

======================================

> >-----Original Message-----
> >From: eddy@fericom.net [mailto:eddy@fericom.net]
> >Sent: 04 February 2002 19:29
>
>
> Hi again Eddy!
>
>
> >- I use the -S option with GCC to learn about the confusing guts of RISC
> > assembler. Is there an option to GCC to add the C lines that produced the
> > assembler as comments? I only found -fverbose-asm but that didn't do.
>
> Yes, the compiler doesn't seem to have any way to do this. The best
> option is to build your code using -g and -O0, then use objdump like:
>
> powerpc-eabi-objdump -SD <.o file name>
>
> to get a listing back.

I'm basically a lurker using the old mc68k cross tools, but
I add the following flags to the gcc compile options to generate a
mixed source and assembly listing - does this help?

-Wa,-adhln,-L -g -c
=========================================
If you compile with "-Wa,-adhln,-L -g -c", you get something like what you want coming up on stdout. (Courtesty of http://sourceware.org/ml/crossgcc/2002-02/msg00019.html)

Also the -fverbose-asm flag can be useful if you just want to know what variable is allocated to what register.



No comments: