In cdecl, is the callee required to preserve the arguments passed to it?

185 Views Asked by At

Say I have void f(int a, int b, int c) { g(a, b, c); h(a, b, c); } in x86 assembly like this:

section .text
f:
    pop dword [res_1]
    call g          ; g(a, b, c)
    call h          ; h(a, b, c)
    push dword [res_1]
    ret
section .bss
res_1:
    resd 1

If g follows the cdecl calling convention, am I guaranteed that g will not alter the parameters passed to it in stack?

1

There are 1 best solutions below

1
On

cdecl does not require callee to preserve it's arguments, but most functions do.

Edit: (add info / answer to comments)

(not relevant after the question has been edited) What about your code: the callee is not required to preserve fpu registers either.

I prefer to believe Agner Fog with it, but you may try to find info in ABIs of your operating systems