Re: Kernel Calling Conventions
- From: spamtrap@xxxxxxxxxx
- Date: Sun, 19 Mar 2006 21:41:19 -0800
There are several considerations in whether to use the stack or
registers for parameter passing.
1. How many registers are available?
2. Is there a stack? A few computers don't have a physical stack, it
must be emulated.
3. How many parameters are expected for a specific call?
4. Is there some special consideration that must be included? e.g.
That the caller always clean up the parameters. This is also a
consideration because of variable length arguments lists for some
functions.
5. Is the efficiency of using a stack comparable with using
registers? If one has a much greater efficiency that might lead you
to using that option for some or all calls.
6. Does the hardware have a real call instruction that is stack
based? I have worked on a system where the 'call' instruction put the
return address into a register and then branched. I also worked on a
mainframe where the COBOL perform of a function put the return address
into a jump at the end of the code. That means no nested calls.
With the x86 and its shortage of general purpose and dedicated
registers, using the stack is more efficient most of the time. I have
used systems that had 48 or more registers. Many were special purpose
for math or indexing. There was another duplicate set of registers
for OS code so it could easily handle interrupts and OS calls without
disturbing program flow unless the scheduler needed to switch tasks.
Read about determining how to optimize code and you will find it is
not easy. I know more optimization should be done, but I find that
using a design that is optimized from the beginning will do more than
any other thing. Not even Intel can predict instruction cycle counts
for more than simple instruction sequences. I still wonder what we
can do with systems that have quad-cores. Maybe just wait faster. ;)
On Mon, 20 Mar 2006 10:31:24 +0800, johnzulu <spamtrap@xxxxxxxxxx>
wrote:
Depends on the situation. With stack you can pass more variables
into the system call. It can be a pain when the register's contents
change after the syscall. But if the parameters of the call are set
minimum , registers can be used without using more memory
for the stack operations.
It depends on your application. For limited memory, I would
go for registers..
john
On 19 Mar 2006 13:14:04 -0800, "Kroll" <spamtrap@xxxxxxxxxx> wrote:
Greetings all,
I was reading the "FreeBSD Assembly Language Programming" tutorial
(http://www.int80h.org/bsdasm/), when I came across something that
piqued my curiosity.
The C calling convention is touted as being more convenient, and
superior to the calling convention used by linux and microsoft of
passing arguments within registers. I was wondering if this is just a
bias on the part of the writer or what.
What are the actual advantages of popping the arguments onto to the
stack as opposed to passing them via registers?
Thanks in advance, :)
Kyle
.
- References:
- Kernel Calling Conventions
- From: Kroll
- Kernel Calling Conventions
- From: johnzulu
- Kernel Calling Conventions
- Prev by Date: Re: problem to compile 32bit code on a 64bit machine
- Next by Date: Re: Kernel Calling Conventions
- Previous by thread: Kernel Calling Conventions
- Next by thread: Re: Kernel Calling Conventions
- Index(es):
Relevant Pages
|