Take the 2-minute tour ×

I am reading one of Agner Fog's manuals and as an advantage for 64 bit Operating Systems (over 32 bit) he says:

Function parameters are transferred in registers rather than on the stack. This makes function calls more efficient.

Is he saying the stack is not used for passing function parameters (64bit OS) at all???

share|improve this question

1 Answer 1

up vote 11 down vote accepted

Yes, that's what he's saying, but it's not quite accurate. The stack may be used, but only if your function has a lot of parameters (or you write code that forces a spill).

If you check out the wikipedia list of 64-bit intel calling conventions, you'll see that registers are used to pass the first several parameters. There are two major 64-bit Intel calling conventions. For the Microsoft ABI:

The Microsoft x64 calling convention uses registers RCX, RDX, R8, R9 for the first four integer or pointer arguments (in that order left to right), and XMM0, XMM1, XMM2, XMM3 are used for floating point arguments. Additional arguments are pushed onto the stack (right to left). Integer return values (similar to x86) are returned in RAX if 64 bits or less. Floating point return values are returned in XMM0. Parameters less than 64 bits long are not zero extended; the high bits contain garbage.

And the System V ABI:

The first six integer or pointer arguments are passed in registers RDI, RSI, RDX, RCX, R8, and R9, while XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6 and XMM7 are used for floating point arguments ... As in the Microsoft x64 calling convention, additional arguments are passed on the stack and the return value is stored in RAX.

share|improve this answer
I guess this is related to another statement he makes saying 64 bit Linux can pass more parameters into registers than Windows 64 bit? "In 64 bit Linux the first six integer parameters and first eight floating point parameters are transferred into registers. In 64 bit Windows the first 4 parameters are transferred....." –  user997112 Jul 2 '13 at 23:04
Yes, that's correct. Linux uses the SYSV ABI, which uses more registers for parameter passing. –  Carl Norum Jul 2 '13 at 23:04
Is that SYSV ABI something which has always been "hidden" within Intel CPUs and that Linux chose to take advantage of, but not Windows? –  user997112 Jul 2 '13 at 23:06
There's nothing about the CPU that affects this behaviour, really. Calling conventions are just that - conventions. It's arbitrary, and they just happen to be different. You could pass parameters in registers for 32-bit code, too (ARM does that for example), there's just not a common Intel ABI that does so. –  Carl Norum Jul 2 '13 at 23:07
More about ABIs from wikipedia. –  Carl Norum Jul 2 '13 at 23:13

Your Answer


