2013-09-05 03:03:51 UTC
1) First can someone clarify for me that all functions will "always" remain in the stack(no where else in memory like the heap or code segments of memory address space)? Here I mean does the code of whatever called function(currently running function) remain on the stack during the whole time of it's execution?
2)What about those functions that will be called later? Do they also get allocated specifically to the stack at the same time as the current executing function or is it after the one finishes executing they get ran by reallocating it's memory and reassigning that stack space to a new function and son on so that the new next function is allocated and deallocated one by one after execution in a top down fashion? What I'm trying to do is eliminate all functions get loaded at the same time or at the time they are called and if they do get loaded at the same time then do they all exist in this area(stack) at the same time?
2) With regards to functions, what are local variables vs global variables? The text I am reading said that the locals variables are in the stack with the function code. Can someone please explain this process from a compiler point of view and how exactly it might get treated?
3) How does the compiler generate the code for the function in the stack and keep order of which one is running and which one will come next? In C with functional programming I can see the order being divided into a hierarchy tree like structure with lists of functions in order on the stack, but in OOP design(again I might not understand it), being a different paradign, does it change the way the stack loads frames? A simple explanation please
4) Does the return statement have relationship to the PC or IR registers? If so please paint a picture so I can better see this at a hardware level.
5) What is the EBP register exactly?
6) Lastly, related to 1 and 2, does the term "stack frame" mean a unit of code for specific function? So that there can be more than one stack frame at a time in the stack? Could I say that to pop a frame by frame model exists? If not please explain if you didn't in 1 and 2 already.
Although I realize this is a lot of questions, I really appreciate anyone who took the time to read and even respond to some of them.