answersLogoWhite

0


Best Answer

Its main use is to store local variables, arguments and return address each time a function is called.

When your program calls a function the following happen :
- The function arguments are put on the stack
- The current instruction pointer is put on the stack
- The program jumps to the start of the function
- Space is allocated on the stack to hold local variables
- The function executes
- The space holding local variables is de-allocated
- The instruction pointer is restored and removed from the stack (we are now leaving the function and resuming the calling procedure)
- The arguments are removed from the stack

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the purpose of the program stack?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the difference between stack pointer and program counter?

The stack pointer keeps track of the top of the stack used by the current thread. The program counter keeps track of the next instruction in a program. Both are registers and both store a memory address.


Why you call programmcounter stack pointer as special purpose resistors?

The Program Counter and Stack Pointer registers are called special purpose registers because they can not be used arbitrarily; they are, well, special. You cannot, for instance, load a new value into the Program Counter and blithely continue, that action would cause an unconditional jump. Also, the Program Counter is automatically incremented by the size of the instruction, so you can not just put something in it and expect its value to persist. Similarly, you cannot load a new value into the Stack Pointer without losing the entire stack context that you are in.


What is Stack overflow at line?

A stack overflow is a type of buffer overflow in which an array writes memory outside of the array boundaries. The keyword here is "stack". The stack is a section in memory in which local variables and other program data are kept for future reference. When the stack gets overflown, adjacent program memory, such as variables, pointers, etc, will be overwritten and cause your program to crash.


Why must the stack pointer be initialized at the beginning of every program?

Because the stack pointer marks the top of the stack. If it is not initialised, it is not possible to determine where the next stack frame will go.


What is the importance of stack algorithm in your program?

Stack implementations allow us to easily implement backtracking algorithms.


Write a c program to perform stack operation?

int top=-1; int stack[10];


Where the exection of program is saved when interrupts occurs?

On the stack.


Which register in the 8085 processor is special purpose?

stack register is a special purpose register.


Stack c language program of palindrome?

what ever you assume


What is difference between stack pointer and program counter?

Both of them are pointers, but otherwise they are completely unrelated. The former points to the current position of the stack, the latter points to the current instruction of the program.


C program to implement tower of hanoi using array implementation of stack abstract datatype?

stack abstract datatype


Can you use stack in microprocessor for storage of data?

Yes, but not for long term storage, only while a program is executing using its stack.