finer details aside (as theres enough here already), the stack's (aka "call stack") primary purpose is to store an address so the control-flow can continue after a subroutine. - A subroutine can be called from multiple locations, so we need to store which location it was in order to return to the correct point. (call and ret are asm functions that will manipulate the stack for you).MilkyGirl wrote:So every process has its own stack?
How do you figure this exactly?
The "stack" would reside in memory, but when I load code from memory, would that already be on the stack?
If not, where would the stack start and end, and where would the stack reside that's not where my bootloader code would be?
Or is the stack briefly some scheme to give the illusion of data in memory? If so, why use it, since all data can theoretically work without it, unless it's hardware specified, and in that case we go back to the drawing board.
I don't get the real purpose, understanding or effectiveness of it really much at all honestly, even reading 500 pages of the "Art of Assembly" guide.
As the stack is used to keep track of where the thread (processing unit) is, you must have one for each thread.(5 people reading a book, they must all know which page and line they are currently reading).
The stack is created at task/thread creation time; When your application is loaded, your application will reserve a space in memory (The data segment) for the stack.