Open In App

Memory Stack Organization in Computer Architecture

A stack is a storage device in which the information or item stored last is retrieved first. Basically, a computer system follows a memory stack organization, and here we will look at how it works.

A portion of memory is assigned to a stack operation to implement the stack in the CPU. Here the processor register is used as a Stack Pointer (SP). The above figure shows the portion of computer memory divided into three segments: Program Instructions, Data, and Stack.



As we can see in the figure, these three registers are connected to a common address bus and either one of them can provide an address for memory.



Stack Pointer is first going to point at the address 3001, and then the stack will grow with the decreasing addresses. It means that the first item is going to be stored at address 3001, the second item at address 3000, and the items can keep getting stored in the stack until it reaches the last address 2000 where the last item will be held.

Here the data which is getting inserted into the Stack is obtained from the Data Register and the data retrieved from the Stack is also read by the Data Register.

Now, let’s see the working of PUSH and POP operations in Memory Stack Organization.

PUSH

This operation is used to insert a new data item into the top of the Stack. The new item can be inserted as follows:-

SP ←SP-1

M[SP]← DR

In the first step, the Stack Pointer is decremented to point at the address where the data item will be stored.

Then, by using the memory write operation, the data item from Data Register gets inserted into the top of the stack ( at the address where the Stack Pointer is pointing).

POP

This operation is used to delete a data item from the top of the Stack. Data item can be deleted as follows:-

DRM[SP]

SPSP+1

In the first step, the top data item is read from the Stack into the Data Register. The Stack Pointer is then incremented to point at the next data item in the stack. Push or Pop operations can be performed with the help of the following microoperations:

It totally depends upon the organization of the stack whether the Stack Pointer (SP) is updated by incrementing or decrementing the address values.

In this case, the Stack Pointer grows by decreasing the memory address. The Stack may be made in a way that the Stack Pointer grows by increasing the memory also.

Since the address is always available and automatically updated in the Stack Pointer, the CPU can refer to the Memory Stack without having to specify an address.

FAQs on Memory Stack Organization

1. From where does the data item are getting stored in the stack?

By using the memory write operation, the data item from the data register gets inserted into the top of the stack.

2. What does Program Counter do?

It points to the address of the next instruction which is going to execute in the program.

3. In memory stack organization, does the stack pointer grow only by decreasing the memory address?

No, It totally depends upon the organization of the stack whether the stack pointer grows by decreasing or increasing the memory address.

Article Tags :