Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
28 views11 pages

Stack & Queue

The document provides an overview of stack organization in computer architecture, highlighting its Last-In-First-Out (LIFO) structure and basic operations such as push, pop, and peek. It discusses two types of stacks: register stacks and memory stacks, detailing their operations and the importance of the stack pointer. Additionally, the document outlines the advantages and disadvantages of using stacks, emphasizing their role in memory management and function calls.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views11 pages

Stack & Queue

The document provides an overview of stack organization in computer architecture, highlighting its Last-In-First-Out (LIFO) structure and basic operations such as push, pop, and peek. It discusses two types of stacks: register stacks and memory stacks, detailing their operations and the importance of the stack pointer. Additionally, the document outlines the advantages and disadvantages of using stacks, emphasizing their role in memory management and function calls.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Stack Organization

An Overview of the LIFO Data Structure

Name : Somanjan Pramanik


Roll No. : 35000322042
Subject : Computer Architecture
College : R.K.M.G.E.C.
Introduction to Stack
A Stack is a linear data structure that follows a
particular order in which the operations are
performed. The order may be LIFO(Last In First
Out) or FILO(First In Last Out). LIFO implies that
the element that is inserted last, comes out
first and FILO implies that the element that is
inserted first, comes out last.
Basic operation of Stack

Push: Adds an item to


the top of the stack.

Pop: Removes the


item from the top of
the stack.

Peek/Top: Returns the


top item without
removing it.
Types
Stack Organization

Register Stack Memory Stack


Register Stack
The stack can be arranged as a set of memory words or registers.
Consider a 64-word register stack arranged as displayed in the figure.
The stack is a set of memory words or registers, with the stack
pointer register holding the address of the element at the top. The
stack consists of three elements: A, B, and C. The top element is
popped by reading memory word at address 3 and decrementing the
stack pointer by 1, while B is pushed by incrementing the stack pointer
by 1 and inserting a new word.

The stack pointer includes 6 bits, because 26 = 64, and the SP cannot
exceed 63 (111111 in binary). After all, if 63 is incremented by 1,
therefore the result is 0(111111 + 1 = 1000000). SP holds only the six
least significant bits. If 000000 is decremented by 1 thus the result is
111111.
Push Pop operation of Register Stack
Push Pop
It can increment stack It can read an element
SP←SP + 1 DR←K[SP] from the top of the
pointer
stack

It can write element on It can decrement the


K[SP] ← DR SP ← SP – 1
top of the stack stack pointer

If (SP = 0) then (FULL


Check if stack is full If (SP = 0) then (EMTY Check if stack is
← 1)
← 1) empty

Mark the stack not


EMTY ← 0 FULL ← 0 Mark the stack not full
empty
Memory Stack
A stack is a storage device where the last stored item is retrieved first. A
computer system follows a memory stack organization, with a portion of
memory assigned to a stack operation in the CPU, using the processor
register as a Stack Pointer.

Program Counter Address Register


Stack Pointer (SP): It
(PC): It is a register (AR): This register
points at the top of
that points to the points at the
the stack and is used
address of the next collection of data
to push or pop the
instruction that is and is used during
data items in or from
going to be executed the execute phase to
the stack
in the program. read an operand.
Function & Push Pop operation
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.
The Stack Pointer points to address 3001, and the stack grows with
decreasing addresses. The first item is stored at 3001, the second at
3000, and the last at 2000. The Data Register obtains and reads data
from the Stack, with items stored at 3001, 3000, and 2000.

Push Pop
SP ←SP-1 DR←M[SP]

M[SP]← DR SP←SP+1
Advantages & Disadvantages

• Simple and Efficient: Stacks are easy • Limited Memory: Stacks' fixed size
to implement and understand, ideal for can lead to stack overflow if too
managing data with LIFO access. much data is pushed.
• Efficient Memory Use: Stacks handle • No Random Access: Unlike arrays,
memory allocation and deallocation, stacks only allow top element
especially for function calls. access, inefficient for certain
• Quick Execution: Stacks are suitable applications.
for managing small datasets in high- • Risk of Overflow: Excessive
performance scenarios like expression recursive calls or large data
evaluation and recursive function storage can cause stack overflow,
management. leading to program crashes.
Conclusion
Stack organization is a crucial computer architecture concept for
memory management, function calls, and program execution,
using a Last-In-First-Out (LIFO) structure. It's essential for CPU
operations but requires careful management in limited memory
resources.

References
✓ www.google.com
✓ www.chatgpt.com
✓ www.geeksforgeeks.com
✓ www.tutorialspoint.com

You might also like