Memory Stack Organization in Computer Architecture
Last Updated :
11 Sep, 2023
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.
- Program Counter (PC): It is a register that points to the address of the next instruction that is going to be executed in the program.
- Address Register (AR): This register points at the collection of data and is used during the execute phase to read an operand.
- Stack Pointer (SP): It points at the top of the stack and is used to push or pop the data items in or from the 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.
.png)
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:-
DR←M[SP]
SP←SP+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:
- Access to memory with the help of Stack Pointer (SP), and
- Updating the stack.
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.
Similar Reads
Memory Organisation in Computer Architecture
Memory organization is essential for efficient data processing and storage. The memory hierarchy ensures quick access to data by the CPU, while larger, slower storage devices hold data for the long term. Effective memory management ensures the system operates efficiently, providing programs with the
3 min read
Cache Memory in Computer Organization
Cache memory is a small, high-speed storage area in a computer. The cache is a smaller and faster memory that stores copies of the data from frequently used main memory locations. There are various independent caches in a CPU, which store instructions and data. The most important use of cache memory
11 min read
Computer Organization - Von Neumann architecture
Computer Organization is like understanding the "blueprint" of how a computer works internally. One of the most important models in this field is the Von Neumann architecture, which is the foundation of most modern computers. Named after John von Neumann, this architecture introduced the concept of
6 min read
Computer Organization and Architecture Tutorial
In this Computer Organization and Architecture Tutorial, youâll learn all the basic to advanced concepts like pipelining, microprogrammed control, computer architecture, instruction design, and format. Computer Organization and Architecture is used to design computer systems. Computer architecture i
5 min read
Computer Organization & Architecture: GATE CSE Previous Year Questions
In this article, we are mainly focusing on the Computer Organization & Architecture GATE Questions that have been asked in Previous Years, with their solutions. And where an explanation is required, we have also provided the reason. Topic-Wise Quizzes to Practice Previous Year's QuestionsCache a
2 min read
Performance of Computer in Computer Organization
In computer organization, performance refers to the speed and efficiency at which a computer system can execute tasks and process data. A high-performing computer system is one that can perform tasks quickly and efficiently while minimizing the amount of time and resources required to complete these
6 min read
Differences between Computer Architecture and Computer Organization
Computer Architecture refers to the design and functional aspects of a computer system, such as the instruction set and processor. Computer Organization deals with the physical implementation and interconnection of hardware components. Computer ArchitectureComputer architecture is the functional des
4 min read
Stack based CPU Organization
Based on the number of address fields, CPU organization is of three types: Single Accumulator organization, register based organization and stack based CPU organization. Stack-Based CPU OrganizationThe computers which use Stack-based CPU Organization are based on a data structure called a stack. The
4 min read
Computer Organization - Basic Computer Instructions
Computer organization refers to the way in which the components of a computer system are organized and interconnected to perform specific tasks. One of the most fundamental aspects of computer organization is the set of basic computer instructions that the system can execute. Basic Computer Instruct
6 min read
Cache Organization | Set 1 (Introduction)
Cache is close to CPU and faster than main memory. But at the same time is smaller than main memory. The cache organization is about mapping data in memory to a location in cache. A Simple Solution: One way to go about this mapping is to consider last few bits of long memory address to find small ca
3 min read