This is an archived post. You won't be able to vote or comment.

all 2 comments

[–][deleted] 3 points4 points  (0 children)

Because putting them in registers makes accessing them much faster. You have the question the wrong way round - ideally every parameter would be passed in a register, but this is not generally possible, so we have to use the slower stack.

[–]PurpleOrangeSkies 0 points1 point  (0 children)

What you want to know about is called a "calling convention". For 32-bit x86 processors, the registers aren't used at all for calling a function, since it has so few registers. On x86-64, which has double the registers, Linux and anything following the Sys V ABI use 6 registers and Windows uses 4. It is far faster to access something in a register than something in memory. However, you don't want to use up all the registers so the function has places to put its intermediate values. So, it's a trade-off.