Question regarding stack alignment

Started by Vortex, May 18, 2025, 09:59:47 PM

Previous topic - Next topic

Vortex

Hello,

Assembling the code below, Poasm Version 13.00.57 reserves 72 bytes on the stack after the declaration of the procedure main :
        sub    rsp, 72
        xor    rax, rax
        mov    qword ptr [rsp+40H], rax
        mov    qword ptr [rsp+38H], rax
        mov    qword ptr [rsp+30H], rax
MessageBoxA PROTO :QWORD,:QWORD,:QWORD,:DWORD
MessageBox TEXTEQU <MessageBoxA>

ExitProcess PROTO :QWORD

.data

msg        db 'Message box example',0
title1      db 'Test',0

.code

start:

    sub    rsp,8+4*8
    call    main
    invoke  ExitProcess,0

main PROC hWnd:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD PARMAREA=4*SIZEOF QWORD

LOCAL x:QWORD
LOCAL y:QWORD
LOCAL z:QWORD

    xor    rax,rax
    mov    x,rax
    mov    y,rax
    mov    z,rax

    invoke  MessageBox,0,ADDR msg,ADDR title1,0
    ret

main ENDP

END start

Any specific reason why Poasm does not reserve 56 bytes instead of 72?

        sub    rsp, 56
The correct stack allocation value should be 56 :

Parmarea -> 4*8 + 3 locals*8 = 56 = 48+8 alignes the stack.
Code it... That's all...

Pelle

It simplifies the code: first align (local-size + parmarea-size), later adjust for uses (push) registers and ultimate stack alignment.
/Pelle

Vortex

Hi Pelle,

Many thanks for the information.
Code it... That's all...