Stack and Heap have no physical presence. They are part of the RAM memory which is used to store the data.
This article is about What is Stack. Why, Where and How is it used?
So, let’s dig deep into the RAM 🌊
- The Stack is an area of RAM where a program stores temporary data during the execution of code blocks.
- It is mainly used during function and interrupt/exception handling.
- The stack is traced using the stack pointer (SP) register of the MCU. Data in the stack memory is added and removed in a LIFO(Last-In-First-Out) manner.
There are two memory access instructions. Which is generally used to Store and Remove data from the Stack Memory.
- PUSH : Add data into the Stack
- POP : Remove data from the Stack
There are four stack suffixes (stack operation models) :
- FD ( Full Descending Stack)
- FA (Full Ascending Stack)
- ED (Empty Descending Stack)
- EA Empty Ascending Stack)
Note:- The Procedure Call Standard for the ARM Architecture (AAPCS), and the ARM and Thumb C and C++ compilers always use a full descending stack.
Full Descending Stack: In this model the stack pointer always points to the last filled data in the stack memory. If we want to push the data into the stack memory then the stack pointer will first decrement the address and then push the data into the stack.
Let’s end this article right here because I need some air…😎 In the comment section you will tell me about other stack operation models.