I have a few questions about EBP, ESP and stack frame in following code.
Why did we subtract 28 from esp? We have two local variables x and y in main. So why didn't we subtract 8?
And don't we put values to stack from right (or top) to left (or bottom)? So why did we add 1 to [eax+8] instead of [eax+4]?
func(int a, int b, int c)
{
return a+b+c;
}
main()
{
int x, y=3;
x=func(y,2,1);
}
gcc -faccumulate-outgoing-args
to make it avoidpush
, instead reserving space and usingmov
relative to ESP. – Peter Cordes[eax+4]
or[eax+8]
addressing modes, and no memory-destination adds. If you want to edit that part of the question into something that makes any sense and matches the answer given, that would probably be good, if you can figure out what you were thinking 8 years ago. (Or if someone else wants to edit.) – Peter Cordes