Is stack in CPU or RAM?

19,822

Solution 1

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.

Solution 2

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.

Solution 3

Which CPU are you talking about?

  1. Some might contain memory that is used for callstacks, some contain memory that can be used for callstacks but require the OS to implement the callstack management code, and others contain no writable memory at all. For example, the x86 architecture tends to have one or more code caches and data caches built into the CPU.

  2. Some CPUs or OSes implement operations that make specific areas of memory non-executable. To prevent stack-based buffer overflows, for example, many OSes use hardware and/or software-based data execution prevention, which might prevent stack memory from being executed as code. Some don't; It's entirely possible that an x86 CPU data cache line might be used to store both the callstack and code to be executed in faster memory.

  3. EIP sounds like a register for the IA32 CPU architecture. If you're referring to IA-32, then yes, it's a CPU operation, though many OSes will switch it to/from RAM to emulate multi-tasking.

Share:
19,822
Admin
Author by

Admin

Updated on July 27, 2022

Comments

  • Admin
    Admin almost 2 years

    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?