1What is stack memory used for in general and how is stack m
1)What is stack memory used for, in general? and how is stack memory used to execute a program subroutine (bsr --- lines of code --- rts)?
Solution
It\'s a special region of your computer\'s memory that stores temporary variables created by each function (including the main() function). The stack is a \"LIFO\" (last in, first out) data structure, that is managed and optimized by the CPU quite closely. Every time a function declares a new variable, it is \"pushed\" onto the stack. Then every time a function exits, all of the variables pushed onto the stack by that function, are freed (that is to say, they are deleted). Once a stack variable is freed, that region of memory becomes available for other stack variables.
The advantage of using the stack to store variables, is that memory is managed for you. You don\'t have to allocate memory by hand, or free it once you don\'t need it any more. What\'s more, because the CPU organizes stack memory so efficiently, reading from and writing to stack variables is very fast.
As the name subprogram suggests, a subroutine behaves in much the same way as a computer program that is used as one step in a larger program or another subprogram. A subroutine is often coded so that it can be started (called) several times and from several places during one execution of the program, including from other subroutines, and then branch back (return) to the next instruction after the call once the subroutine\'s task is done. Maurice Wilkes, David Wheeler, and Stanley Gill are credited with the invention of this concept, which they termed a closed subroutine,[2][3] contrasted with an open subroutine or macro

