save %sp, -96, %spand that this instruction will decrement the stack pointer by 96 and thus reserve 96 bytes on the system stack.
When the SPARC CPU executes a save instruction and there is no more unused register windows available, the operating system will intervene.
The operating system is a program that is running inside the computer which manages the resources of the computer system - e.g., Windows 98, 2000, ME, XP,... in the Sun, the operating system is called "Solaris")
When SPARC detects this, it will use the stack pointer in the register window (shaded yellow in the figure) to find the stack segment that was reserved for saving the registers (see the red arrow)
Although the SPARC CPU has only 8 sets of register windows, the Operating System can "recycle" the register windows and make it appear as it the user has a VERY LARGE set of windows
In fact, SPARC can use the entire computer memory for this "recycling" trick and you have virtually an unlimited number of register windows....
Recall that when we try to write recursion in M68000, we cannot pass parameters in registers because M68000 has only ONE set of registers and it was not possible for us to "create new register"
In fact, we have "delegated" the problem of creating new variables on the stack to the Operating System - as you have seen above, SPARC's operating system will take care of saving the window registers away for us....
main: int n, r; Write("n = "); // Prompt user to enter n n = ReadInt(); // Read in number r = fac(n); Write("fac = "); WriteInt(r); int fac(int n) { int sol; if ( n == 0 ) return(1); else { sol = fac(n-1); return (n * sol); } }
main: int n, r; Write("n = "); // Prompt user to enter n n = ReadInt(); // Read in number r = fib(n); Write("fib = "); WriteInt(r); int fib(int n) { int h1, h2; if ( n == 0 ) return(1); esle if ( n == 1 ) return(1); else { h1 = fib(n-1); h2 = fib(n-2); return (h1 + h2); } }
main: int n; Write("Number of disks = "); // Prompt user to enter n n = ReadInt(); // Read in number hanoi(n, 1, 3); // from peg 1 to peg 3 void hanoi(int ndisks, int fromPeg, int toPeg) { int helpPeg; if (ndisks == 1) then WriteLn "move disk from peg " + fromPeg + " to " + " + toPeg else { helpPeg := 6 - fromPeg - toPeg; hanoi(ndisks-1, fromPeg, helpPeg); WriteLn "move disk from peg " + fromPeg + " to " + " + toPeg hanoi(ndisks-1, helpPeg, toPeg); } }
class List { int value; List next; } main: int n; List head; // Start of list List ptr; // Points to new list element head = NULL; while(TRUE) { Write("Enter number: "); // Prompt user to enter n n = ReadInt(); // Read in number ptr = malloc(8); ptr.value = n; head = Insert(head, ptr); PrintList(head); } List Insert(List head, List elem) { List help; if head == null) { // Base case elem.next = null; return(elem); // New head } else { // Recursion help = Insert(head.next, elem); // Insert elem in shorter list head.next = help; // Link return list AFTER // the first elem in orig. list return(head); // head is unchanged } }