|
|
|
|
|
by amluto
3262 days ago
|
|
Registers aren't all that valuable on architectures with reasonable numbers of them, and a lot of architectures do "branch and link" instead of an x86-style call. Branch and link generally means that control flow jumps elsewhere and the address of the next instruction is stored in a register. You jump back to that register to return. Functions are responsible for saving the link register if they clobber it. This has at least one benefit over x86-style calls: a function like this: void foo(void)
{
for (int i = 0; i < 10; i++)
some_leaf_function();
}
has to save its own return address to the stack, but it only needs to save it once, so all ten leaf calls can happen without stack access for the return address.Of course, architectures like x86 have specialized hardware to optimize calls, so it's probably a wash in the end. |
|