Stack Based CPU Organization
Stack Based CPU Organization is implemented through Registers. It Follows the Rule Last In First Out (LIFO). To add data in stack we use PUSH and to remove we will use POP. Stack organization can be implemented on RAM or Registers.
Implementation of Registers as a Stack.
Here we explain the Implementation of registers as a stack. Mostly 64 general registers are use for stack implementation, so 6 bits are require to address 64 registers. SP is a stack pointer (top of the stack) which is use to store the address of that location where we have to push or pop any data. As SP stores the address of that location where we PUSH or POP data, so its size will be 6 bits. We use two flags registers named as FULL and EMPTY.
- If the value of FULL is 1, then Empty will be zero and vice versa.
- and If FULL value is 1 then it means there is no more space to enter any new data.
- If EMPTY value is 1 than it means we can add new data is stack organized registers.
How to PUSH DATA?
As in diagram SP points Zero. When we want to add any data from the data register to the stack register. SP incremented by 1 and Points the first general register having address 1. If we want to add new data then SP incremented to again and data will be pushed to the second general register and so on. In this way, 63 (1 to 63) data values can be added to different 64 general-purpose registers. When 64th data value is add to the 64-register stack organization then SP points to ZERO because (64= 1000000). As SP size is 6-bits and a higher bit is discarded and least 6-bits are considered. So, SP value becomes (000000=0). When SP=0 then FULL=1 and EMPTY=0 which means there is no more space to PUSH 65th data value in stack.
How to POP Data?
If we want to retrieve data from stack to Data Register then we use POP command. Memory location of SP Address is POP and sends data to Data Register. SP, decremented by 1. In same way next memory location of SP address is POP. We can remove more data from stack until SP points to zero. When SP=0 then EMPTY =1 and FULL=0. It means all stack is empty.