Just started to learn the x64 build, and I have a question about functions, arguments, and the stack. As far as I understand, the first four arguments to the function are passed to the rcx, rdx, r8 and r9 registers (and xmm0-xmm3 for floats) on Windows. Thus, a trivial add function with four parameters would look like this:
add: mov r10, rcx add r10, rdx add r10, r8 add r10, r9 mov rax, r10 ret
However, I came across documentation that mentions this :
. At a minimum, each function should reserve 32 bytes (four 64-bit values) on the stack. This space allows you to easily rewrite the registers passed to the function to a well-known location of the stack. A call function is not required to distinguish between the parameters of the input register on the stack, but the reservation of the stack space ensures that it can if necessary.
So, do I need to reserve stack space even if my functions take four parameters or less, or is this just a recommendation?
assembly stack 64bit cpu-registers
Don Sep 12 '11 at 18:39 2011-09-12 18:39
source share