The window register is used to:
- Pass parameters to functions
- Reserve (private) registers that are used as local
variables of functions
- Pass return value back to caller function
done in the manner as shown in the following figure:
Example:
main()
{
main's local variables;
....
return_value = func(param0, param1);
}
func(int x, int y)
{
func's local variables;
....
return(...);
}
According to the figure, we can use the window registers to pass parameters
and result values as follows:
- main() passes param0 and param1 using o0 and o1
in main's window
- Then main() calls func()
- The first thing that func() must do is
"move the window down".
- We do this primarily to preserve the local variable
of main() and prevent it from being accessed and destroyed by func().
- However, the effect of this is that the parameters
passed by main() in registers o0 and o1
are now being accessed as i0 and i1 !!!
- func() can now operate, but be aware that the parameters are in
i0 and i1.
func() can use registers L0, ..., L7 as local variables
(these registers will not be shared)
- When func() is ready to return, it must put the return
value in one of the input registers !
- Before func() retruns back to main(), it must
"move the window up" !!! (because it was func() who moved it down,
"clean up you own mess" !)
- After func() returns back to main(), main() can receive
the return values in its output registers !!!