I tried to run the simple code below:
extrn MessageBoxA: PROC
extrn ExitProcess: PROC
.data
titles db 'Win64', 0
msg db 'Hello World!', 0
.code
main proc
    sub rsp, 28h      ; 32 byte for 4 arguments, 8 byte for 'call' it self
    mov rcx, 0        ; hWnd = HWND_DESKTOP
    lea rdx, msg      ; LPCSTR lpText
    lea r8,  titles   ; LPCSTR lpCaption
    mov r9d, 0        ; uType = MB_OK
    call MessageBoxA
    mov ecx, eax
    add rsp, 28h
main endp
End
When I move it to a function the code no longer works:
extrn MessageBoxA: PROC
extrn ExitProcess: PROC
.data
titles db 'Win64', 0
msg db 'Hello World!', 0
msgbox_ready:
sub rsp, 28h      ; 32 byte for 4 arguments, 8 byte for 'call' it self
mov rcx, 0        ; hWnd = HWND_DESKTOP
lea rdx, msg      ; LPCSTR lpText
lea r8,  titles   ; LPCSTR lpCaption
mov r9d, 0        ; uType = MB_OK
call MessageBoxA
mov ecx, eax
add rsp, 28h
.code
main proc
  call msgbox_ready
main endp
End
If I move the contents of msgbox_ready to function main it seems to be okay. What is the issue? Can it be because its outside of .code section?