Question

I'm currently learning x64 assembly by myself and have trouble understanding what happen with the stack when calling an assembly procedure from c++.

From what I currently understand from MSDN and Intel, the first 4 integer/floating point parameters are stored in the rcx/xmm0, rdx/xmm1, r8/xmm2 and r9/xmm3 registers and all others will be placed on the stack.

I just do not understand why i have to access the 5th parameter 40 bytes from rsp [rsp+28h] instead of just 8 since the first 32 bytes are accessed in registers.

Can someone explain me what actually happens?

Thank you.

Was it helpful?

Solution

The key is in this phrase from the linked MSDN:

The x64 Application Binary Interface (ABI) is a 4 register fast-call calling convention, with stack-backing for those registers.

That is, the registers are loaded with the first 4 arguments, but nevertheless they have its space reserved in the stack. As @HansPassant notes in the comments below, the caller does not write into this shadow space, but it is available for the callee, should it need to save the registers (for example for calling another function).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top