I'm not understating why the parameters to printf are passed this way. mov [esp+20h+var_1C], eax mov [esp+20h+Format], offset Format ; "%d"
Why esp is added with 20h then substracted with 20h and esp doest added to point to next stack location for local vars ?
why the compiler simply didnt generate code like this: move eax, var_4 push eax move eax, Format push eax call printf
Ill be happy i some of you can either explain how push is replaced with this custom mov.
here is the source in c:
#include <stdio.h>
int main(void)
{
int a;
int b = 5;
printf("%d", b);
return 0;
}
here is the disassembly:
; Attributes: bp-based frame
; int __cdecl main(int argc, const char **argv, const char **envp)
public _main
_main proc near
Format= dword ptr -20h
var_1C= dword ptr -1Ch
var_4= dword ptr -4
argc= dword ptr 8
argv= dword ptr 0Ch
envp= dword ptr 10h
push ebp
mov ebp, esp
and esp, 0FFFFFFF0h
sub esp, 20h
call ___main
mov [esp+20h+var_4], 5
mov eax, [esp+20h+var_4]
mov [esp+20h+var_1C], eax
mov [esp+20h+Format], offset Format ; "%d"
call _printf
mov eax, 0
leave
retn
_main endp