The Wayback Machine - https://web.archive.org/web/20241004130334/https://www.geeksforgeeks.org/memory-stack-organization-in-computer-architecture/
Open In App

Memory Stack Organization in Computer Architecture

Last Updated : 11 Sep, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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.

Memory Stack Organization

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.

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.



Similar Reads

Computer Organization and Architecture | Computer Organization and Architecture | Question 1
Where does the swap space reside? (A) RAM (B) Disk (C) ROM (D) On-chip cache Answer: (B) Explanation: Quiz of this Question
1 min read
Differences between Computer Architecture and Computer Organization
It is very important for any person who is interested or has a leaning towards computer science or anybody who has to work with computers to understand the difference between computer architecture and computer organization. What needs to be understood is that although these two concepts are interconnected they are different, one deals with the smal
5 min read
Computer Organization and Architecture | Pipelining | Set 3 (Types and Stalling)
Please see Set 1 for Execution, Stages and Performance (Throughput) and Set 2 for Dependencies and Data Hazard. Types of pipeline Uniform delay pipeline In this type of pipeline, all the stages will take same time to complete an operation. In uniform delay pipeline, Cycle Time (Tp) = Stage Delay If buffers are included between the stages then, Cycl
3 min read
Computer Organization and Architecture | Pipelining | Set 2 (Dependencies and Data Hazard)
Please see Set 1 for Execution, Stages and Performance (Throughput) and Set 3 for Types of Pipeline and Stalling. Dependencies in a pipelined processor There are mainly three types of dependencies possible in a pipelined processor. These are : 1) Structural Dependency 2) Control Dependency 3) Data Dependency These dependencies may introduce stalls
6 min read
Computer Organization and Architecture | Pipelining | Set 1 (Execution, Stages and Throughput)
Pipelining is a technique used in modern processors to improve performance by executing multiple instructions simultaneously. It breaks down the execution of instructions into several stages, where each stage completes a part of the instruction. These stages can overlap, allowing the processor to work on different instructions at various stages of
9 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 is that it is used to reduce the average time to
9 min read
Stack Frame in Computer Organization
Stack Frame :Stack is one of the segments of application memory that is used to store the local variables, function calls of the function. Whenever there is a function call in our program the memory to the local variables and other function calls or subroutines get stored in the stack frame. Each function gets its own stack frame in the stack segme
3 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 InstructionsBasic computer instructions are the elementary
7 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 tasks. The performance of a computer system depen
6 min read
Why Linked List is implemented on Heap memory rather than Stack memory?
Pre-requisite: Linked List Data StructureStack vsHeap Memory Allocation The Linked List is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements in a linked list are linked using pointers. It is implemented on the heap memory rather than the stack memory. This article discusses the reason behind
14 min read
Direct Memory Access (DMA) Controller in Computer Architecture
DMA Controller is a hardware device that allows I/O devices to directly access memory with less participation of the processor. DMA controller needs the same old circuits of an interface to communicate with the CPU and Input/Output devices. What is a DMA Controller?Direct Memory Access uses hardware for accessing the memory, that hardware is called
5 min read
Memory Organisation in Computer Architecture
The memory is organized in the form of a cell, each cell is able to be identified with a unique number called address. Each cell is able to recognize control signals such as “read” and “write”, generated by CPU when it wants to read or write address. Whenever CPU executes the program there is a need to transfer the instruction from the memory to CP
2 min read
2D and 2.5D Memory organization
The internal structure of Memory either RAM or ROM is made up of memory cells that contain a memory bit. A group of 8 bits makes a byte. The memory is in the form of a multidimensional array of rows and columns. In which, each cell stores a bit and a complete row contains a word. A memory simply can be divided into this below form. 2n = N where n i
4 min read
Cache Hits in Memory Organization
The user has a memory machine. It has one layer for data storage and another layer for the cache. The user has stored an array with length N in the first layer. When the CPU needs data, it immediately checks in cache memory whether it has data or not. If data is present it results in CACHE HITS, else CACHE MISS, i.e., data is not in cache memory so
8 min read
Terminologies Cache Memory Organization
Cache Memory is a small, fast memory that holds a fraction of the overall contents of the memory. Its mathematical model is defined by its size, number of sets, associativity, block size, sub-block size, fetch strategy, and write strategy. Any node in the cache hierarchy can contain a common cache or two separate caches for instruction and or data.
4 min read
Introduction of Stack based CPU Organization
The computers which use Stack-based CPU Organization are based on a data structure called a stack. The stack is a list of data words. It uses the Last In First Out (LIFO) access method which is the most popular access method in most of the CPU. A register is used to store the address of the topmost element of the stack which is known as Stack point
3 min read
Computer Organization | Amdahl's law and its proof
It is named after computer scientist Gene Amdahl( a computer architect from IBM and Amdahl corporation) and was presented at the AFIPS Spring Joint Computer Conference in 1967. It is also known as Amdahl's argument. It is a formula that gives the theoretical speedup in latency of the execution of a task at a fixed workload that can be expected of a
6 min read
Computer Organization | Micro-Operation
In computer central processing units, micro-operations (also known as micro-ops) are the functional or atomic, operations of a processor. These are low level instructions used in some designs to implement complex machine instructions. They generally perform operations on data stored in one or more registers. They transfer data between registers or
3 min read
Computer Organization | Different Instruction Cycles
Introduction : Prerequisite - Execution, Stages and Throughput Registers Involved In Each Instruction Cycle: Memory address registers(MAR) : It is connected to the address lines of the system bus. It specifies the address in memory for a read or write operation.Memory Buffer Register(MBR) : It is connected to the data lines of the system bus. It co
11 min read
Computer Organization | Asynchronous input output synchronization
Introduction : Asynchronous input/output (I/O) synchronization is a technique used in computer organization to manage the transfer of data between the central processing unit (CPU) and external devices. In asynchronous I/O synchronization, data transfer occurs at an unpredictable rate, with no fixed timing or synchronization between the CPU and ext
7 min read
MPU Communication in Computer Organization
MPU communicates with the outside world with the help of some external devices which are known as Input/Output devices. The MPU accepts the binary data from input devices such as keyboard and analog/digital converters and sends data to output devices such as printers and LEDs. For performing this task, MPU first need to identify the input/output de
4 min read
Purpose of an Interrupt in Computer Organization
Interrupt is the mechanism by which modules like I/O or memory may interrupt the normal processing by CPU. It may be either clicking a mouse, dragging a cursor, printing a document etc the case where interrupt is getting generated. Why we require Interrupt? External devices are comparatively slower than CPU. So if there is no interrupt CPU would wa
2 min read
Peripherals Devices in Computer Organization
Generally peripheral devices, however, are not essential for the computer to perform its basic tasks, they can be thought of as an enhancement to the user's experience. A peripheral device is a device that is connected to a computer system but is not part of the core computer system architecture. Generally, more people use the term peripheral more
4 min read
Data Manipulation Instructions in Computer Organization
Data Manipulation Instructions Data manipulation instructions perform operations on data and provide computational capabilities for the computer. The data manipulation instructions in a typical computer are usually divided into three basic types as follows. Arithmetic instructionsLogical and bit manipulation instructionsShift instructions Let's dis
3 min read
Control Logic Gates in Computer Organization
Control Logic Gates is the hardware component of a basic computer. It comprises some inputs and outputs. The diagram given below is related to the hardwired control organization. The diagram below consists of the instruction register which has three parts: the I bit (15), the operation code (12, 13, 14), and bits 0 through 11. The symbols as D0 to
2 min read
Synchronous Data Transfer in Computer Organization
In Synchronous Data Transfer, the sending and receiving units are enabled with the same clock signal. It is possible between two units when each of them knows the behaviour of the other. The master performs a sequence of instructions for data transfer in a predefined order. All these actions are synchronized with the common clock. The master is des
4 min read
Computer Organization | Hardwired v/s Micro-programmed Control Unit
Introduction : In computer architecture, the control unit is responsible for directing the flow of data and instructions within the CPU. There are two main approaches to implementing a control unit: hardwired and micro-programmed. A hardwired control unit is a control unit that uses a fixed set of logic gates and circuits to execute instructions. T
5 min read
BUS Arbitration in Computer Organization
Introduction : In a computer system, multiple devices, such as the CPU, memory, and I/O controllers, are connected to a common communication pathway, known as a bus. In order to transfer data between these devices, they need to have access to the bus. Bus arbitration is the process of resolving conflicts that arise when multiple devices attempt to
7 min read
RISC and CISC in Computer Organization
RISC is the way to make hardware simpler whereas CISC is the single instruction that handles multiple work. In this article, we are going to discuss RISC and CISC in detail as well as the Difference between RISC and CISC, Let's proceed with RISC first. Reduced Instruction Set Architecture (RISC) The main idea behind this is to simplify hardware by
5 min read
Computer Organization | Instruction Formats (Zero, One, Two and Three Address Instruction)
In computer organization, instruction formats refer to the way instructions are encoded and represented in machine language. There are several types of instruction formats, including zero, one, two, and three-address instructions. Each type of instruction format has its own advantages and disadvantages in terms of code size, execution time, and fle
11 min read