Stack-Based CPU Organization

Stack-based CPU Organization is implemented through Registers. It Follows the Rule of Last In, First Out (LIFO). To add data in the stack, we use PUSH, and to remove it, we will use POP. Stack organization can be implemented on RAM or Registers.

Register Stack Organization

Implementation of Registers as a Stack.

Here, we explain the Implementation of registers as a stack. Mainly, 64 general registers are used for stack implementation, so 6 bits are required to address 64 registers. SP is a stack pointer (top of the stack) that stores the location’s address where we must push or pop any data. As SP stores the address of that location where we PUSH or POP data, its size will be 6 bits. We use two flag registers named FULL and EMPTY.

  • If the value of FULL is 1, then Empty will be zero, and vice versa.
  • If the FULL value is 1, then there is no more space to enter any new data.
  • If the EMPTY value is 1, then it means we can add new data in stack-organized registers.

How to PUSH DATA?

As in the diagram, SP points to Zero. When we want to add data from the data, register to the stack register. SP was incremented by 1, and Points is the first general register addressing 1. If we want to add new data, then SP is incremented again, and data will be pushed to the second general register, and so on. This way, 63 (1 to 63) data values can be added to 64 general-purpose registers. When the 64th data value is added to the 64-register stack organization, then SP points to ZERO because (64= 1000000). As the SP size is 6 bits, a higher bit is discarded, and the last 6 bits are considered. So, the SP value becomes (000000=0). When SP=0, FULL=1, and EMPTY=0, there is no more space to PUSH the 65th data value in the stack.How to PUSH DATA - CPU Organization

How to POP Data?

If we want to retrieve data from the stack to the Data Register, then we use the POP command. The memory location of the SP Address is POP and sends data to the Data Register. SP, decremented by 1. In the same way, the next memory location of the SP address is POP. We can remove more data from the stack until SP points to zero. When SP=0, then EMPTY =1 and FULL=0. It means all the stack is empty.

How to POP DATA - CPU Organization