gcc assembler output oddness

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Please forgive me if I'm emailing the wrong list. I was referred by the gcc
documentation.

Hello, I'm a student having a bit of trouble compiling with gcc. I attempted to
compile a few programs with the -S option, and got pretty strange results... is
this a feature, or something I somehow should understand?

I copied below the files outputed and what I expected. Some instructions are of
extreme strangeness, such as

mov $0, %eax
subl %eax, %esp

What is the point of doing this? For one thing, stdcall doesn't require %eax to
be zeroed(or does it?). Whatmore, it's totally weird and useless to subtract
zero from any value, especially considering no conditional jump follows...

So what am I missing?

thank you,
Kazuo
kazuo@xxxxxxxxxxxxxxxx

#########################################
# file 1: the code the way i expected it
#########################################
	.file	"blah.c"
	.section	.rodata
.LC0:
	.string	"hello world\n"
	.text
.globl somefunc
	.type	somefunc,@function
somefunc:
	pushl	%ebp
	movl	%esp, %ebp
	pushl	$.LC0
	call	printf
	leave
	ret
.Lfe1:
	.size	somefunc,.Lfe1-somefunc
.globl main
	.type	main,@function
main:
	pushl	%ebp
	movl	%esp, %ebp
	call	somefunc
	movl	$0, %eax
	leave
	ret
.Lfe2:
	.size	main,.Lfe2-main
	.ident	"kaz 0.0001"



#################################
# file 2: the code by gcc 3.2.3
#################################
	.file	"blah.c"
	.section	.rodata
.LC0:
	.string	"hello world\n"
	.text
.globl somefunc
	.type	somefunc,@function
somefunc:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	subl	$12, %esp
	pushl	$.LC0
	call	printf
	addl	$16, %esp
	leave
	ret
.Lfe1:
	.size	somefunc,.Lfe1-somefunc
.globl main
	.type	main,@function
main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	andl	$-16, %esp
	movl	$0, %eax
	subl	%eax, %esp
	call	somefunc
	movl	$0, %eax
	leave
	ret
.Lfe2:
	.size	main,.Lfe2-main
	.ident	"GCC: (GNU) 3.2.3"




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux