Linux asm code
- From: spamtrap@xxxxxxxxxx
- Date: Thu, 29 Sep 2005 18:49:42 +0000 (UTC)
I have compiled a useless C module with Gcc under Linux just to see
what compiled C code looks like. The C code is this:
print1(char * str)
{
printf(str);
}
The output asm code is as follows (generated by objdump)
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 the "top" four
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
.
- Follow-Ups:
- Re: Linux asm code
- From: Andrei Voropaev
- Re: Linux asm code
- Prev by Date: Re: Clever ways to hide a compare
- Next by Date: Accessing Debug Registers in Linux
- Previous by thread: c++ inline assembler and oop
- Next by thread: Re: Linux asm code
- Index(es):
Relevant Pages
|