Why does this function allocate more stack space than it needs to, before calling gets()
?
echo:
pushl %ebp
movl %esp, %ebp
pushl %ebx
leal -8(%ebp), %ebx
subl $20, %esp <-- Why so much space?
movl %ebx, (%esp)
call gets
...
The corresponding C code:
void echo()
{
char buf[4];
gets(buf);
puts(buf);
}
Why is there an additional extra space of three words between the buffer and the argument for gets?
There are two sentences in the book Computer Systems. "gcc adhere to an x86 programming guideline that the total stack space used by the function should be multiple of 16 bytes." and "Including the 4 bytes for the saved %ebp and the 4 bytes for the return address,"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With