Stack distribution, why extra space?

I played a little to deal better with calls and how to handle the stack, but I can’t understand why main selects three additional double words when setting up stack (c <main+0>). It does not match either 8 bytes or 16 bytes, so I don’t know as far as I know. As I can see, main requires 12 bytes for two parameters for func and return value.

What am I missing?

The program is C code compiled using "gcc -ggdb" in the x86 architecture.

Edit: I removed the -O0 flag from gcc and it had no meaning for the output.

(gdb) disas main
Dump of assembler code for function main:
    0x080483d1 <+0>:    sub    esp,0x18
    0x080483d4 <+3>:    mov    DWORD PTR [esp+0x4],0x7
    0x080483dc <+11>:   mov    DWORD PTR [esp],0x3
    0x080483e3 <+18>:   call   0x80483b4 <func>
    0x080483e8 <+23>:   mov    DWORD PTR [esp+0x14],eax
    0x080483ec <+27>:   add    esp,0x18
    0x080483ef <+30>:   ret    
End of assembler dump.

Edit: Of course, I had to post the C code:

int func(int a, int b) {
    int c = 9;
    return a + b + c;
}

void main() {
    int x;
    x = func(3, 7);
}

The platform is Arch Linux i686.

+4
2

. - , esp , .

gcc 16 , .

+2

(, main), . , , . , int, (eax, 32- x86).

, , main :

int main(int argc, char **argv) { 
   char a[35];

   return 0;
}

... 35 , , main, a. 32- , 4 ( 36), 32- . - , . argc argv , , main, main , .

, a, a [esp-36], argv [esp-44], argc [esp-48] ( - , ). , [esp-40], .

: :

enter image description here

2: , , , , . main main, , , main.

, ( ).

+4

Source: https://habr.com/ru/post/1016216/


All Articles