The MASM Forum

64 bit assembler => 64 bit assembler. Conceptual Issues => Topic started by: TWell on September 16, 2016, 02:24:22 AM

Title: x64 C compiler code
Post by: TWell on September 16, 2016, 02:24:22 AM
if someone compile this code with msvc 2015 with option -Ox#define WIN32_LEAN_AND_MEAN
#include <windows.h>

void __cdecl WinMainCRTStartup(void)
{
ExitProcess(WinMain(GetModuleHandle(NULL),0,0,SW_SHOW));
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
MessageBox (NULL, "Hello World!", "Hello", MB_OK);
return 0;
}
getsWinMain LABEL NEAR
        sub     rsp, 40                                 ; 0000 _ 48: 83. EC, 28
        xor     r9d, r9d                                ; 0004 _ 45: 33. C9
        lea     r8, [$SG30964]                          ; 0007 _ 4C: 8D. 05, 00000000(rel)
        lea     rdx, [$SG30965]                         ; 000E _ 48: 8D. 15, 00000000(rel)
        xor     ecx, ecx                                ; 0015 _ 33. C9
        call    qword ptr [__imp_MessageBoxA]           ; 0017 _ FF. 15, 00000000(rel)
        xor     eax, eax                                ; 001D _ 33. C0
        add     rsp, 40                                 ; 001F _ 48: 83. C4, 28
        ret                                             ; 0023 _ C3

same with gcc 6WinMain LABEL NEAR
        sub     rsp, 40                                 ; 0000 _ 48: 83. EC, 28
        lea     r8, [?_001]                             ; 0004 _ 4C: 8D. 05, 00000000(rel)
        xor     r9d, r9d                                ; 000B _ 45: 31. C9
        xor     ecx, ecx                                ; 000E _ 31. C9
        lea     rdx, [?_002]                            ; 0010 _ 48: 8D. 15, 00000006(rel)
        call    qword ptr [__imp_MessageBoxA]           ; 0017 _ FF. 15, 00000000(rel)
        xor     eax, eax                                ; 001D _ 31. C0
        add     rsp, 40                                 ; 001F _ 48: 83. C4, 28
        ret                                             ; 0023 _ C3
EDIT: not relevant after all
Title: Re: x64 C compiler code
Post by: jj2007 on September 16, 2016, 03:28:22 AM
IMHO add rsp, 20h would be sufficient in this case.