I am trying to understand how the amount of bytes to substract from esp is calculated in a 32 bit machine. I understand that it is done in order to create a stack frame and that the bytes are multiples of 8, but I can't figure out why a specific amount is allocated. I created some mock functions but I still have some questions.
// push ebp
// mov ebp,esp
// call <func>
// pop ebp
// ret
int main() {
func();
}
^ no sub esp command
// push ebp
// mov ebp,esp
// sub esp,0x10 // sub of 16 bytes
// mov DWORD PTR [ebp-0x4],0x5
// leave
// ret
void func2() {
int n = 5;
}
^ sub of 16 - why not 8 if int is 4 bytes?
// push ebp
// mov ebp,esp
// sub esp,0x18 // sub of 24 bytes
// mov DWORD PTR [ebp-0xc],0x5
// call <func4>
// leave
// ret
void func3() {
int m = 5;
func4();
}
^ sub of 24 - why not 16, if function call in main didn't
have a sub command and func had a sub of 16 ?