cdecl calling convention은 c에서 주로 쓰는 calling convention으로, 스택을 통해 인자를 전달하며 caller가 stack을 정리하고, return 값은 eax로 전달을 받는 규약입니다.
가장 기본 형태는 아래와 같죠. (visual studio 등)
위와 같이 push 대신 esp와 esp+(n*4)에 mov 해버립니다.
즉 인자를 전달할 때 esp가 늘어나지 않습니다. 제자리에서 esp 아래쪽에 write를 하는거죠.
이런 방식으로 전달을 하면 cdecl 함수 호출시 스택을 보정해줄 필요가 없습니다.
인자를 두개 받는 stdcall이라, 호출 후에
sub esp, 0x8을 해주는군요.
'cdecl' calling convention is used in 'c'. it passes parameters through
stack, and caller cleans the stack. return values are delivered through
eax.
this is the basic form of cdecl.(visual studio .,)
take a look at
add esp, 0x8 after calling printf with two arguments.
caller knows how many parameters he put(two), he cleans the stack.
add esp, 8
merits are that it handles variable-length arguments nicely,
there are hundreds of posts talking about calling conventions you can search.
now, gcc deals with cdecl in an interesting way.
never mind with mov eax, 0x0i just included it in the screenshot so that you can see there is no add esp, 0x8
instead of pushing arguments in the stack, it moves them at esp+(n*4) .
which means, esp does not change when passing arguments. it writes the values below esp.
with this method, you don't have to re-modify esp after calling cdecl functions.
actually, you have to modify esp when calling stdcall functions,
which are never used.
you can check it out.
myfunc is a stdcall function. you can see
sub esp, 0x8 after callin' it.