1. 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.
2. 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.
3. 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.
5. 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.
6. Push Pop operation of Register Stack
SP SP + 1
←
It can increment
stack pointer
K[SP] DR
←
It can write element
on top of the stack
If (SP = 0) then (FULL
1)
←
Check if stack is full
EMTY 0
←
Mark the stack not
empty
DR K[SP]
←
It can read an
element from the top
of the stack
SP SP – 1
←
It can decrement the
stack pointer
If (SP = 0) then (EMTY
1)
←
Check if stack is
empty
FULL 0
←
Mark the stack not
full
Push Pop
7. 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.
Memory
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
8. 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.
SP SP-1
←
M[SP] DR
←
DR M[SP]
←
SP SP+1
←
Push Pop
9. • Simple and Efficient: Stacks are easy
to implement and understand, ideal
for managing data with LIFO access.
• Efficient Memory Use: Stacks handle
memory allocation and deallocation,
especially for function calls.
• Quick Execution: Stacks are suitable
for managing small datasets in high-
performance scenarios like
expression evaluation and recursive
function management.
• Limited Memory: Stacks' fixed
size can lead to stack overflow if
too much data is pushed.
• No Random Access: Unlike
arrays, stacks only allow top
element access, inefficient for
certain applications.
• Risk of Overflow: Excessive
recursive calls or large data
storage can cause stack overflow,
leading to program crashes.
Advantages &
Disadvantages
10. Conclusio
n
Reference
s
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.
www.google.com
www.chatgpt.com
www.geeksforgeeks.com
www.tutorialspoint.com