Below is an illustration of the stack concept:
I have read many times about the stack pointer and how some variables are stored in SRAM on a stack.
Many tutorials explain how it works, but not why this concept exist at all.
Imagine I am the program and I want to store my cup, my watch and my hat in my room. Why would I store them on top of each other instead of putting them in random places in my room?
Program can reach the data as long as it has its address. But if the stack pointer puts x on the top y. How will it reach y without removing x then? So to me a stack must make things (data access) even harder.
Can you give a very simple example with registers or assembly code or C code to illustrate the benefit of this stacking concept, namely "Last in, first out" (LIFO)?