This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Stack Frame Problem


Hello everybody

I'm working at a highschool in Rapperswil, Switzerland. We teach students on
informatics and therefore there is a need we can explain why things works as
they do. No we got a serious problem explaining, why passing parameters over
stack is handled different on the i386 and the i686 compiled C-code. In i386
parameters are pushed to lower adresses than the stack pointer, on i686
parameters are moved to higher adresses than the stack pointer.

For your information:
- When compiling C-code for the i386 platform, the parameters are pushed to
the stack, when passing zwo parameters to a function for example, a frame of
16 byte is reserved and the first 8 bytes (the ones with the higher
addresses) are not used. The parameters are pushed towards lower adresses,
compared to the start address of the stack pointer.
- When compiling for the i686 platform, the compiler looks for the function
with the most parameters and puts the stackpointer at a position, so that
the parameters can be passed to higher adresses, compared to the start
adress of the stack pointer. When passing the parameters to the stack, the
stack pointer is not moved, the parameters are placed by a movl command
relative to the stack pointer position (no push is used), towards higher
adresses then the stack pointer position.

We have a problem to explain, why the compiler programmer have changed that
style. I thought, this could be for performance-reason (different CPU
architecture), but a measurement with a small program has not confirmed
that. Even whorse, the i386 code was ~1% faster (!).

So, if anybody knows why that happens, or knows a place on the internet,
where there is information about this, I would highly appreciate to get a
message.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]