Stack Organization ~ Computer System Architecture

Prince Prajapati
0

Stack Organization

A stack, also known as a Last in First out (LIFO) list, is a crucial component of a CPU. It efficiently stores data, retrieving the most recently stored element first. The stack consists of a memory unit equipped with an address register called the Stack Pointer (SP). The SP determines the address of the top element in the stack. The stack allows for two fundamental operations: insertion (push operation) and deletion (pop operation). Pushing involves adding an element to the stack, while popping involves removing an element from the stack. These operations are simulated by incrementing or decrementing the SP register.

There are two ways to implement a stack:

• Register Stack 
• Memory Stack

Register Stack 

In a Register Stack, the stack can reside in a portion of a larger memory or be organized as a collection of a fixed number of memory words or registers. For instance, let's consider a stack of 64 words with elements A, B, and C added in that order. With C on top of the stack, the content of SP becomes 3. To remove the top item, the stack is popped by reading the memory word at address 3 and decrementing the SP content. As a result, B becomes the new top of the stack since SP holds address 2. To insert a new item, the stack is pushed by incrementing SP and writing a word in the next higher location in the stack.

The PUSH operation involves the following micro operations:

1. Incrementing the stack pointer (SP← SP+1),
2. Writing the item on top of the stack (M[SP] <- DR),
3. Whecking if the stack is full (if SP=0, then set the "full" flag to 1). 
4. Mark the stack not empty (Empty <- 0)

The POP operation includes the following micro operations: 

1. Reading the item from the top of the stack (DRE <- M[SP]), 
2. Incrementing the stack pointer (SP<-SP-1),
3. Checking if the stack is empty ( if(SP-0) then (EMPTY<-1) ),
4. Marking the stack as not full (FULL <-0).

Memory Stack

In the Memory Stack implementation, the stack is realized in RAM connected to the CPU. A dedicated portion of memory is assigned for stack operations, and a processor register serves as the stack pointer. A block diagram of the 64-word stock memory stack is presented. In this diagram, three segments are shown: the Program Counter (PC) indicating the address of the next instruction in the program, the Data segment representing an array of data, and the Stack Pointer (SP) pointing to the top of the stack. These three registers are interconnected through a common address bus, enabling any of them to provide an address for memory access.
PUSH Operation as follows:-
SP<-SP-1 
M [SP] <-DR. 

To insert a new item using the PUSH operation, the stack pointer is decremented (SP<-SP-1), and the item is written to the memory location pointed by SP (M[SP] <- DR). 

POP operation as follows:-
DR<-M [SP] 
SP<-SP+1 

Deleting an item using the POP operation involves reading the item from the memory location pointed by SP (DR<-M[SP]), incrementing the stack pointer (SP<-SP+1), and performing checks for stack limits using two processor .


Tags:

Post a Comment

0Comments

Post a Comment (0)