0

I came across this code in RE4B book, page 66:

$SG2923 DB    'a=%d; b=%d; c=%d; d=%d; e=%d; f=%d; g=%d; h=%d', 0aH, 00H
main    PROC
        sub    rsp, 88
        mov    DWORD PTR [rsp+64], 8
        mov    DWORD PTR [rsp+56], 7
        mov    DWORD PTR [rsp+48], 6
        mov    DWORD PTR [rsp+40], 5
        mov    DWORD PTR [rsp+32], 4
        mov    r9d, 3
        mov    r8d, 2
        mov    edx, 1
        lea    rcx, OFFSET FLAT:$SG2923
        call   printf
        xor    eax, eax
        add    rsp, 88
        ret    0
main    ENDP
_TEXT   ENDS 
END

Why did the compiler decide to reference the arguments starting from [rsp+64] till [rsp+32]?

Shouldn't the last argument be at [rsp]?

Why it didn't start from [rsp+32] till [rsp] so the callee can reference its arguments from [rsp]?

Or this is something due to that the first 3 arguments are being passed in registers?

You can notice that GCC is doing what I am trying to say, starting referencing & finishing at [rsp]: enter image description here

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847

0 Answers0