What is the hardware stack?
The first part of the answer is: what is a stack?
If we are talking about data structures in general, a stack is a data structure, a container with two operations:
- A new element can be placed on top of the stack (push)
- The top element can be taken away from the stack (pop)
What is the hardware stack? It is an emulation of stack in the existing memory,
where every byte has its address.
There is no a separate stack memory.
The emulation is implemented with help of:
rsp
register, the stack pointer, which points at the last element that was put into stack.- Machine instructions, that use
rsp
to identify the top of the stack. They are pushing and popping elements from the stack and changingrsp
accordingly. Examples of such instructions are: push
pop
call
ret
int