What is Stack. Why, Where and How is it used?

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. 

  1. PUSH : Add data into the Stack 
  2. POP : Remove data from the Stack

Both instructions affect the stack pointer register value (increment or decrement). 

There are four stack suffixes (stack operation models) :

  1. FD ( Full Descending Stack) 
  2. FA (Full Ascending Stack) 
  3. ED (Empty Descending Stack) 
  4. 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.

Leave a Comment

Your email address will not be published. Required fields are marked *