Unused stack space
michael_quinlivan_at_hotmail.com
Date: 09/30/05
- Previous message: nikhilbhargav_nsit_at_coolgoose.com: "Re: help in a multiplayer network fighting game..."
- Next in thread: QNils_O=2E_Sel=E5sdal=22?=: "Re: Unused stack space"
- Reply: QNils_O=2E_Sel=E5sdal=22?=: "Re: Unused stack space"
- Reply: Basile Starynkevitch [news]: "Re: Unused stack space"
- Reply: Josef Moellers: "Re: Unused stack space"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Sep 2005 22:45:53 -0700
In a C module that I have compiled, it seems to generate object files
which waste stack space. The C file is as follows
print1(char * str)
{
printf(str);
}
yes I know it is useless, it was simply created so that I could examine
how GCC generates asm code, which is below
>objdump -d print1.o
00000013 <print1>:
13: 55 push %ebp
14: 89 e5 mov %esp,%ebp
16: 83 ec 08 sub $0x8,%esp
19: 8b 45 08 mov 0x8(%ebp),%eax
1c: 89 04 24 mov %eax,(%esp)
1f: e8 fc ff ff ff call 20 <print1+0xd>
24: c9 leave
25: c3 ret
The code is relatively simple, but I don't understand the third
instruction (sub 0x8, esp). obviously it allocates 8 bytes to the
stack, but why does it allocate this much? It only uses 4 bytes of it
(to pass the str parameter to printf), and leaves four bytes unused.
Why is this? Or am I confusing something??
My mental image of the stack just before the call to printf is as
follows. Is this accurate?
|Param to print1 |
|--------------------|
|Addr of caller |
|--------------------|
|Caller EBP |
|--------------------|
|UNUSED DWORD |
|--------------------|
|Param to printf |
|--------------------|
cheers
MQ
- Previous message: nikhilbhargav_nsit_at_coolgoose.com: "Re: help in a multiplayer network fighting game..."
- Next in thread: QNils_O=2E_Sel=E5sdal=22?=: "Re: Unused stack space"
- Reply: QNils_O=2E_Sel=E5sdal=22?=: "Re: Unused stack space"
- Reply: Basile Starynkevitch [news]: "Re: Unused stack space"
- Reply: Josef Moellers: "Re: Unused stack space"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|