Here is a simple program in C for which I used gdb to disassemble it to understand what is happening.
#include <stdio.h>
#include <string.h>
int main(){
printf("%d", sizeof(foo("HELLOWORLD")));
}
int foo(char* c)
{
printf("%s\n",c);
}
And below is the corresponding assembly code for disassemble main
0x08048414 <+0>: push %ebp
0x08048415 <+1>: mov %esp,%ebp
0x08048417 <+3>: and $0xfffffff0,%esp
0x0804841a <+6>: sub $0x10,%esp
0x0804841d <+9>: mov $0x8048520,%eax
0x08048422 <+14>: movl $0x4,0x4(%esp)
0x0804842a <+22>: mov %eax,(%esp)
0x0804842d <+25>: call 0x8048320 <printf@plt>
0x08048432 <+30>: leave
0x08048433 <+31>: ret
And below is disassemble foo
0x08048434 <+0>: push %ebp
0x08048435 <+1>: mov %esp,%ebp
0x08048437 <+3>: sub $0x18,%esp
0x0804843a <+6>: mov 0x8(%ebp),%eax
0x0804843d <+9>: mov %eax,(%esp)
0x08048440 <+12>: call 0x8048330 <puts@plt>
0x08048445 <+17>: leave
0x08048446 <+18>: ret
I m confused about these instructions:
0x08048417 <+3> and $0xfffffff0,%esp
Why stack pointer needs to be aligned when it is not modified before?0x0804841a <+6>:sub $0x10,%esp
what exactly is this instruction doing particular to the program?0x0804841d <+9>:mov $0x8048520,%eax
what is this instruction doing particular to the program?mov %eax,(%esp)
What does parenthesis around%esp
mean?
Would be helpful if someone explained this.