MASM32 Downloads
3.9 Directive OPTION WIN64..INVOKE Stack Space Reservation [bit 1]: ..- 1: the maximum stack space required by all INVOKEs inside a procedure is computed by the assembler and reserved once on the procedure's entry. It's released when the procedure is exited.
option casemap:noneoption frame:autooption win64:1include DlgBox.incinclude invoke.inc.dataDlgBox db 'DLGBOX',0.codestart PROC sub rsp,8+5*8+8 _invoke GetModuleHandle,0 _invoke DialogBoxParam,rax,ADDR DlgBox,0,ADDR DlgProc,0 _invoke ExitProcess,raxstart ENDPDlgProc PROC hWnd:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD sub rsp,4*8 .IF uMsg==WM_CLOSE _invoke EndDialog,hWnd,0 .ELSE xor rax,rax ret .ENDIF mov eax,1 retDlgProc ENDPEND
_text SEGMENT PARA 'CODE' start PROC sub rsp, 56 xor rcx, rcx call GetModuleHandleA mov rcx, rax mov rdx, offset DlgBox xor r8, r8 mov r9, offset DlgProc mov qword ptr [rsp+20H], 0 call DialogBoxParamA mov rcx, rax call ExitProcess DlgProc LABEL NEAR mov qword ptr [rsp+8H], rcx mov qword ptr [rsp+10H], rdx mov qword ptr [rsp+18H], r8 mov qword ptr [rsp+20H], r9 push rbp mov rbp, rsp sub rsp, 32 cmp qword ptr [rbp+18H], 16 jnz ?_001 mov rcx, qword ptr [rbp+10H] xor rdx, rdx call EndDialog jmp ?_002 ?_001: xor rax, rax leave ret start ENDP?_002 LABEL NEAR mov eax, 1 leave ret
so that all you have to do is select RBP or RSP as stackbase .. and the rest is automatic.