Stack Pointers

When a piece of program code calls a subroutine, control eventually returns from that subroutine to the caller.The calling code expects the state of the machine to be fundamentally the same as when the subroutine was invoked.Since all instructions on a modern computer work with the same set of registers, some of the register values need to be preserved before the subroutine starts working, so they can be restored after it is finished.High-level programming languages provide the ability to pass multiple parameters to functions, oftentimes more parameters than the number of registers available.Locally scoped variables available only to the subroutine are also commonly used in higher-level languages.All of these things can be implemented by using a stack, or last-in-first-out queue.

MIPS-architecture machines use the $sp register by convention as the stack pointer, the last-used memory location where elements on the stack have been recorded.When a program is loaded on the processor, $sp is initially set to the highest address in a block of memory reserved for the stack.