Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 05 Mar 2004 23:01:09 +0100
From:      ISAAC GELADO FERNANDEZ <igf@tid.es>
To:        Chungwei Hsiung <skuma17@yahoo.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: A simple question
Message-ID:  <2c8b6a2ce3cf.2ce3cf2c8b6a@tid.es>

next in thread | raw e-mail | index | archive | help
> ISAAC GELADO FERNANDEZ wrote:
> 
> >De: Chungwei Hsiung <skuma17@yahoo.com>
> >Fecha: Viernes, Marzo 5, 2004 7:43 pm
> >  
> >
> >>I have a simple test program. I compile it, 
> >>and 
> >>gdb to disassemble main. I got the following..
> >>
> >>0x80481f8 <main>:       push   %ebp
> >>0x80481f9 <main+1>:     mov    %esp,%ebp
> >>0x80481fb <main+3>:     sub    $0x8,%esp
> >>0x80481fe <main+6>:     and    $0xfffffff0,%esp
> >>0x8048201 <main+9>:     mov    $0x0,%eax
> >>0x8048206 <main+14>:    sub    %eax,%esp
> >>
> >>I don't know if at line 5, we move zero to %eax. why do we need 
> to sub %eax, %esp? why do we need to subtract 0 from the stack 
> pointer??>>    
> >>
> > 
> > I am no really sure, but it maybe be because you don't have any 
> local variable, so it is no necessary to allocate memory in the 
> stack for them. This seems a pattern from the compiler, it subtract 
> the size of local variables from the stack pointer, so when there 
> is none it subtracts zero. But this is just a supposition
> > 
> >
> >
> thank you for the reply..
> I try it again to call a function with local variables, but it does 
> that 
> as well. I think that line is not a part of a function prologue 
> because 
> when I try it with or without local variables, it is always there. 
> any 
> ideas??
> btw.. the compiler I use is gcc 3.2.2


I have performed some tests and the "strange" code apperars always. 

At first I thought the compiler puts the code to align the stack, but if you write a function it doesn't appear.

Maybe the compiler puts the subl to set system flags to a known value, but I don't really know.

I will try to obtain a good answer, I am really intrigate ;)

Regards,
 Isaac

> 
> best regards
> Chungwei
> 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2c8b6a2ce3cf.2ce3cf2c8b6a>