Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is stack in CPU or RAM?

Tags:

I have a few question about stack.

  1. Is stack in CPU or RAM?
  2. Is stack a place to run OPcode?
  3. Is EIP in CPU or RAM?
like image 997
abiati madana Avatar asked Mar 15 '13 13:03

abiati madana


People also ask

Is the stack on RAM?

Stack is used for static memory allocation and Heap for dynamic memory allocation, both stored in the computer's RAM . Variables allocated on the stack are stored directly to the memory and access to this memory is very fast, and it's allocation is dealt with when the program is compiled.

Where is the stack located?

Stacks often are placed in the uppermost address regions of the machine. They usually grow from the highest memory location towards lower memory locations, allowing the maximum flexibility in the use of the memory between the end of program memory and the "top" of the stack.

Is RAM a stack or heap?

While a stack is used mainly for static memory allocation, a heap is used for dynamic memory allocation. One of the things stack and heap have in common is that they are both stored in a computer's RAM.

Is stack pointer in CPU?

Stack engineSimpler processors store the stack pointer in a regular hardware register and use the arithmetic logic unit (ALU) to manipulate its value. Typically push and pop are translated into multiple micro-ops, to separately add/subtract the stack pointer, and perform the load/store in memory.


2 Answers

Stack is always in RAM. There is a stack pointer that is kept in a register in CPU that points to the top of stack, i.e., the address of the location at the top of stack.

like image 108
unxnut Avatar answered Nov 17 '22 09:11

unxnut


The stack is found within the RAM and not within the CPU. A segment is dedicated for the stack as seen in the following diagram:

enter image description here

From Wiki:

The stack area contains the program stack, a LIFO structure, typically located in the higher parts of memory.

like image 42
Goaler444 Avatar answered Nov 17 '22 07:11

Goaler444