Why does gcc use stack area without decrementing stack pointer?

54 Views Asked by At

For this simple C program,

int test(int a,int b)
{
    int k=89;
    return a+b;
}
int main()
{
    test(5,3);
}

gcc 10 produces the following assembly code (using https://godbolt.org/ and verified on my machine):

test:
        push    rbp
        mov     rbp, rsp
        mov     DWORD PTR [rbp-20], edi
        mov     DWORD PTR [rbp-24], esi
        mov     DWORD PTR [rbp-4], 89
        mov     edx, DWORD PTR [rbp-20]
        mov     eax, DWORD PTR [rbp-24]
        add     eax, edx
        pop     rbp
        ret
main:
        push    rbp
        mov     rbp, rsp
        mov     esi, 3
        mov     edi, 5
        call    test
        mov     eax, 0
        pop     rbp
        ret

As you can see, gcc is using stack area without decrementing stack pointer. Is this normal? Isn't gcc supposed to decrement esp before using stack area?

0

There are 0 best solutions below