7 ms·
>Why does Linux pass arguments in registers instead of using the stack? It's a convention. Depending on your architecture, compiler and API, it uses the stack
by mappu 12y ago
>Why does Linux pass arguments in registers instead of using the stack?
It's a convention. Depending on your architecture, compiler and API, it uses the stack in a lot of cases (cdecl/stdcall on i386). Linux on AMD64 always uses the SYSV ABI which uses registers as much as possible (i'm assuming for performance reasons, since 'fastcall' does the same on i386).
- raverbashing 12y agoI didn't know that was the name of it, interesting, though it sounds like an Anachronism http://en.wikipedia.org/wiki/X86_calling_conventions#System_V_AMD64_ABI http://en.wikipedia.org/wiki/X86_calling_conventions#System_...
- gwu78 12y ago"It's a convention." Does Minix use that convention? How about BSD?
- icebraining 12y ago"The calling convention of the System V AMD64 ABI is followed on Solaris, Linux, FreeBSD, Mac OS X, and other UNIX-like or POSIX-compliant operating systems." http://en.wikipedia.org/wiki/X86_calling_conventions#System_V_AMD64_ABI http://en.wikipedia.org/wiki/X86_calling_conventions#System_...
- gwu78 12y agoint80h.org Anyway, the original question was _why_ does Linux use registers to pass arguments. Arguments can be passed on the stack, but Linux chose to use registers. Why this choice over the other option? Do you know the answer? Just curious.
- icebraining 12y agoIt's because in theory, it's faster to copy the values to registers than to have to push them all to the stack and then have the callee pop them. At least that was the thought behind Microsoft's __fastcall, which was their original version of a calling convention using registers, though in that case it seems the benchmarks aren't conclusively in support of the theory.