[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Variable length arguments in C/C++
- From: Sean Conner <sean@...>
- Date: Tue, 9 Aug 2022 22:53:32 -0400
It was thus said that the Great Paul Ducklin once stated:
> > Not only are some of the register names
> > different, but the calling convention is
> >different between x86-32 bit (parameters
> > passed on the system stack) and x86-6
> > bit (first six parameters passed in registers,
> > rest on the system stack
> By convention, X64 calls have up to four parameters passed in registers
> (RCX, RDX, R8 and R9). Any additional parameters are pushed on the stack
> in reverse order.
For Windows. For Solaris, Linux, FreeBSD and MacOS, it's six registers
(RDI RSI RDX RCX R8 R9) and any additional parameters are pushed on the
stack in reverse order.
> Functions put their return value in RAX, if there is one.
This is true for Linux, Solaris, FreeBSD and MacOS.
> (After pushing any needed stack parameters, the stack pointer is then
> shifted downwards to leave room for four temporary values on the stack -
> the called function can use this space for whatever it likes, such as
> temporary storage of register parameters. At this point the desired
> function is CALLed. Oh, and you are supposed to ensure that whenever a
> CALL happens, the stack pointer RSP is a multiple of 16.)
Again, for Windows; I am unsure of for other systems. A decent place to
start is the Wikipedia article:
-spc (So yeah, to repeat what I said earlier---this is non-portable, and
it really depends upon the architecture and OS)