Although parameters can be passed in registers if the called function is not recursive, the compiler will not attempt to make this check and will usually pass parameters on the stack because this method will work for both recursive and non-recursive functions.
SPARC tries to eliminate the need to access memory by putting the following inside registers:
Code in Java/C/C++:
============================================================
main(...) ----> int func(int x, int y, int z)
{ / {
... / ...
... / ...
r = func(a, b, c) return(value);
^ } |
| |
+--------------------------------------+
...
}
Assembler code in a traditional (e.g. M68000) computer:
============================================================
main: ... func: Save frame pointer of
... my caller
... Allocate local variables
Push parameters on stack on stack
Call func ....
Pop params off the stack .... (function body)
Assign return value to ....
its destination
... Pass return value in
a register
Deallocate local variables
from stack
Restore frame pointer
of my caller
Return to my caller
Assembler code in SPARC:
============================================================
main: ... func: + Save frame pointer of
... my caller
... + Obtain my own copy of
Push parameters in local registers
Output registers + Allocate space on stack
Call func ....
Pop params off the stack .... (function body)
Assign return value to ....
its destination
... Pass return value in
an input register
+ Return local registers
+ Deallocate locaL
variables from stack
+ Restore frame pointer
of my caller
Return to my caller
The computer can make it "look like" it has more register windows by saving a set of register window (all input, local and output registers) to memory when the register window overflow is detected. The place to save the overflow register window is on the stack.