Stack Terminology
1. Context. The environment in which a function executes includes argument values local variables and global variables all the context the global variables is stored in a stack frame.
2. Stack frames. The data structure containing all the data (arguments local variables return address etc) needed each time a procedure or function is called.
3. MAXSIZE. This term is not a standard one, we use this term to refer the maximum size of stack,
4. Top. This term refers to the top of stack (TOS). The stack top is used to check stack overflow or underflow conditions. Initially Top stores - 1. This assumption is taken so that whenever an element is added to the stack the Top is first incremented and then the item is inserted into the location currently indicated by the Top,
5. Stack. It is an array of size MAXSIZE.
6. Stack empty or underflow. This is the situation when the stack contains no element. At this point top of stack is present at the bottom of the stack.
7. Stack overflow. This is the situation when the stack becomes full and no more elements can be pushed onto the stack. At this point the stack top is present at the highest location of the stack.
Stack frames
Almost invariably programs complied from modern high level languages (even C) make use of a stack frame for the working memory of each procedure or function invocation. When any procedure or functions is called, a number of words- the stack frame - is pushed onto a program stack. When the procedure or function returns this frame of data is popped off the stack.
As a function calls another function first its arguments then the return address and finally space for local variables is pushed onto the stack, since each function runs in its own environment or context it becomes possible for a function to call function to call itself- a technique known as recursion. This capability is extremely useful and extensively used because many problems are elegantly specified or solved in a recursive way.
Program stack after executing a pair of mutually recursive functions:
Function f (int x, int y){
Int a;
If (term_cond) return.................;
A =.................;
Return g(a);
Function g(int Z)
{
Int p,q;
P = .... ; q=....;
Return f(p,q);
}
Note how all of functions f and g's environment (their parameters and local variables) are found in the stack frame. When f is called a second time from g, a new frame for the second invocation of f is created.
The stack is a region of main memory within which programs temporarily store data as they execute.
ExpertsMind.com - Stack Terminology Assignment Help, Stack Terminology Homework Help, Stack Terminology Assignment Tutors, Stack Terminology Solutions, Stack Terminology Answers, Stack Assignment Tutors