SlideShare a Scribd company logo
1MADE BY RIDA ZAMAN
STACK
 Stack is a data structure in which last item inserted is taken
out first
 It works in LIFO manner (last in first out)
2MADE BY RIDA ZAMAN
OPERATIONS ON STACK
 We can perform two operation on a stack
 INSERTION (PUSH)
 DELETION (POP)
3MADE BY RIDA ZAMAN
STACK ORGANIZATION
IN STACK ORGANIZATION WE STORE OR PLACE OUR
DATA IN A MANNER OF A STACK.
4MADE BY RIDA ZAMAN
STACK POINTER
 It’s an register which is used to store the address of the top
item in the stack
 It’s a 6-bit register
5MADE BY RIDA ZAMAN
DATA REGISTER
Whatever value we INSERT(PUSH) or DELETE(POP)
from the stack it stores in data register
It’s a 2byte register /16bits
6MADE BY RIDA ZAMAN
TYPES OF STACK ORGANIZATION
There are two types of stack organization we have for our
CPU
 REGISTER STACK
 MEMORY STACK
7MADE BY RIDA ZAMAN
REGISTER STACK
 If we have for example finite number of words which we
want to insert at top of another and making stack out of it
through register stack.
8MADE BY RIDA ZAMAN
SINGLE BIT REGISTER
We have two single bit registers
 FULL: If the entire stack is full then this full register will
set to be 1
 EMPTY: If the entire stack is empty then this empty
register will set to be 1
9MADE BY RIDA ZAMAN
ALGORITHM FOR PUSH
 SPSP+1
 M{SP}DR
 IF(SP=0)THEN (F1)
 EMPTY0
10MADE BY RIDA ZAMAN
ALGORITHM FOR PUSH
STEP BY STEP
 SPSP+1 Increment stack by a value 1
 M{SP}DR Whatever content present in data register
place it inside the memory word to which stack pointer is
presently pointing
 IF(SP=0)THEN (F1) We are performing push
operation so we may encounter a position where our stack
would become full so we have to set our full bit to 1
 If our stack pointer is equal to zero set full=1
 EMPTY0 Because we are putting values into the stack
so its not empty anymore
11MADE BY RIDA ZAMAN
ALGORITHM FOR POP
 DRM{SP}
 SPSP-1
 IF {SP=0}{EMPTY1}
 FULL0
12MADE BY RIDA ZAMAN
ALGORITHM FOR POP
STEP BY STEP
 DRM{SP}Whatever content I have in the memory word
that the stack pointer is pointing at present store it in the
data register
 SPSP-1 The stack pointer should point to the next top
element ,it must be decremented by a value-1
 IF{SP=0}{EMPTY1} We are performing POP operation
so we may encounter a position where our stack would
become entirely empty at that point we will set empty =1
 FULL0 Because we are deleting values from stack so its
obvious that it wont become full at any point
13MADE BY RIDA ZAMAN
MEMORY STACK
 In Memory stack we have a Memory Unit
 In memory unit we divide memory into 3 portions
 PROGRAM(INSTRUSTIONS): it is use to access/fetch
instructions from memory
 DATA(OPERANDS): it is use to access/fetch data and
operands from memory
 STACK: it is use to push or pop item into the stack
 In memory stack our stack grows with decreasing address
 There is different algorithm for both memory and register
stacks
14MADE BY RIDA ZAMAN
MEMORY UNIT
15MADE BY RIDA ZAMAN
ALGORITHM’S
PUSH POP
SPSP-1
M{SP}DR
DRM{SP}
SPSP+1
16MADE BY RIDA ZAMAN
ALGORITHM FOR PUSH
STEP BY STEP
 SPSP-1 The first operation we will do is we will
decrement our stack pointer
 M{SP}DR Whatever data we have in the data register we
should place it at the memory word at which the stack
pointer is pointing at
17MADE BY RIDA ZAMAN
ALGORITHM FOR POP
STEP BY STEP
 DRM{SP} Whatever content I have in the memory word
of stack pointer I have to place it into data register
 SPSP+1 Then we’ll increment our stack pointer by 1
18MADE BY RIDA ZAMAN
DIFFERENCE BETWEEN
REGISTER STACK AND MEMORY STACK
 The stack grows with
increasing address in
register stack
 Register stack is generally
on the CPU
 Access to register stack is
fast
 Register stack is limited size
wise
 The stack grows with
decreasing address in
register stack
 Memory stack is on the
RAM(main memory)
 Access to memory stack is
not as fast as register stack
 Memory stack is larger then
register stack size wise
19MADE BY RIDA ZAMAN
PRACTICAL APPLICATION
OF HOW STACK
ORGANIZATION WORKS
INSIDE OUR CENTRAL
PROCESSING UNIT
20MADE BY RIDA ZAMAN
DIFFERENT NOTATIONS WE HAVE IN
REPRESENTING ARITHMETIC NOTATIONS
 INFIX
 PREFIX (POLISH NOTATION)
 POSTFIX (REVERSE POLISH NOTATION/RPN)
21MADE BY RIDA ZAMAN
INFIX NOTATION
 In INFIX notation we have to write the operator in
between the operands
22MADE BY RIDA ZAMAN
PREFIX NOTATION
 In PREFIX notation we have to write the operator before
the operands
 Most of the computer use PREFIX notation to execute
arithmetic operations
23MADE BY RIDA ZAMAN
POSTFIX
(REVERSE POLISH NOTATION/RPN)
 In POSTFIX notation we have to write the operator after
the operands
24MADE BY RIDA ZAMAN
EXAMPLE:
25MADE BY RIDA ZAMAN
SO WHAT THE COMPUTER DOES?
 It scan the particular expression from left to right whenever
it encounters an operator it does the particular operation on
the previous two elements/operands that are scanning
26MADE BY RIDA ZAMAN
HOW STACK ORGANIZATION
IS USE TO EVALUATE
ARITHEMATIC
EXPRESSIONS
27MADE BY RIDA ZAMAN
WHEN AN OPERATOR IS
ENCOUNTERED
 The two top most elements in the stack are use for the
operation
 The stack is popped and the result of the operation replaces
the lower operand
28MADE BY RIDA ZAMAN
EXAMPLE:
29MADE BY RIDA ZAMAN
30MADE BY RIDA ZAMAN

More Related Content

PPT
Computer Organization and Architecture.
PPTX
Direct memory access (dma)
PPT
Structure of a C program
PPTX
Infix to postfix conversion
PPTX
UNIT 10. Files and file handling in C
PPTX
Input-Buffering
PPTX
RECURSIVE DESCENT PARSING
PPTX
memory hierarchy
Computer Organization and Architecture.
Direct memory access (dma)
Structure of a C program
Infix to postfix conversion
UNIT 10. Files and file handling in C
Input-Buffering
RECURSIVE DESCENT PARSING
memory hierarchy

What's hot (20)

PPTX
Memory Reference Instructions
PPTX
Stack and its usage in assembly language
PPTX
Memory organization (Computer architecture)
PPTX
Cache Memory
PPTX
Computer registers
PDF
FUNCTIONS IN C PROGRAMMING.pdf
PPT
Memory management
PPTX
Booth’s algorithm.(a014& a015)
PPTX
Register & flags
PPT
File handling in c
PPTX
PPTX
stack & queue
PPTX
Stack organization
PPTX
Pipeline processing and space time diagram
PDF
Infix to postfix expression in ds
PPTX
Timing and control
PPTX
Input Output Organization
PPTX
Dynamic memory allocation
PPTX
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Memory Reference Instructions
Stack and its usage in assembly language
Memory organization (Computer architecture)
Cache Memory
Computer registers
FUNCTIONS IN C PROGRAMMING.pdf
Memory management
Booth’s algorithm.(a014& a015)
Register & flags
File handling in c
stack & queue
Stack organization
Pipeline processing and space time diagram
Infix to postfix expression in ds
Timing and control
Input Output Organization
Dynamic memory allocation
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Ad

Similar to Stack Operations (20)

PDF
7BCEE2A - UNIT V - STACK ORGANIZATION.pdf
PDF
Central processing unit
PPTX
Central processing unit pptx for computer engineering
PDF
Lect12 organization
PPTX
stack.pptx stack overflow in computer organisations
DOCX
Computer Organization and 8085 microprocessor notes
PPTX
UNIT-3.pptx
PPT
CH-3 CPU Computer architecture and organization.ppt
PPTX
2024_lecture11__come321.pptx.......................
PPTX
EC502fggggggggggggggggggggmmmmmmmmmmmmmmmmmmc
PPTX
Stack and its operations
PDF
UNIT-3-COrtertertertertertertertertr.pdf
PPT
unit-3-L1.ppt
PPT
CO by Rakesh Roshan
PPT
central processing unit.ppt
PPT
CAO_Unit-3.ppt
PPT
Stack & queue
PPTX
Data structure
PPT
computer organisation unit 3 presentatio
7BCEE2A - UNIT V - STACK ORGANIZATION.pdf
Central processing unit
Central processing unit pptx for computer engineering
Lect12 organization
stack.pptx stack overflow in computer organisations
Computer Organization and 8085 microprocessor notes
UNIT-3.pptx
CH-3 CPU Computer architecture and organization.ppt
2024_lecture11__come321.pptx.......................
EC502fggggggggggggggggggggmmmmmmmmmmmmmmmmmmc
Stack and its operations
UNIT-3-COrtertertertertertertertertr.pdf
unit-3-L1.ppt
CO by Rakesh Roshan
central processing unit.ppt
CAO_Unit-3.ppt
Stack & queue
Data structure
computer organisation unit 3 presentatio
Ad

More from RidaZaman1 (20)

PDF
Strategy Experiments in Nonexperimental Settings_ Challenges of Theory, Infer...
PPTX
Overview of the Subject of Human Resource Management
PPTX
career management.pptx
PPTX
Computer Networks
PPTX
Restricting the recruitment and selection.pptx
PPTX
performance appraisal and management.pptx
PPTX
Managing HR Globally, Strategically Managing the HR.pptx
PPTX
HR Development & Career Systems.pptx
PPTX
Health & Wellness Management.pptx
PPTX
Coaching Sponsoring And Mentoring.pptx
PPTX
Purchasing and Supplier Selection.pptx
PPTX
micro teaching.pptx
PPTX
challenges faced by HR in the 21st century.pptx
PPTX
mcdonalds.pptx
PPTX
The Role of Creativity In Entrepreneurship.pptx
PPTX
JOB Analysis
PPTX
ON & OFF THE JOB TRAINING
PPTX
Nestle
PPTX
Case Study on Ihavemoved.com
PDF
Product Life Cycle of Coca Cola Pakistan
Strategy Experiments in Nonexperimental Settings_ Challenges of Theory, Infer...
Overview of the Subject of Human Resource Management
career management.pptx
Computer Networks
Restricting the recruitment and selection.pptx
performance appraisal and management.pptx
Managing HR Globally, Strategically Managing the HR.pptx
HR Development & Career Systems.pptx
Health & Wellness Management.pptx
Coaching Sponsoring And Mentoring.pptx
Purchasing and Supplier Selection.pptx
micro teaching.pptx
challenges faced by HR in the 21st century.pptx
mcdonalds.pptx
The Role of Creativity In Entrepreneurship.pptx
JOB Analysis
ON & OFF THE JOB TRAINING
Nestle
Case Study on Ihavemoved.com
Product Life Cycle of Coca Cola Pakistan

Recently uploaded (20)

PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Complications of Minimal Access Surgery at WLH
PDF
01-Introduction-to-Information-Management.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Lesson notes of climatology university.
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Institutional Correction lecture only . . .
PPTX
master seminar digital applications in india
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Cell Structure & Organelles in detailed.
PDF
Pre independence Education in Inndia.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Basic Mud Logging Guide for educational purpose
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Complications of Minimal Access Surgery at WLH
01-Introduction-to-Information-Management.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Lesson notes of climatology university.
Sports Quiz easy sports quiz sports quiz
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Microbial disease of the cardiovascular and lymphatic systems
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Institutional Correction lecture only . . .
master seminar digital applications in india
102 student loan defaulters named and shamed – Is someone you know on the list?
GDM (1) (1).pptx small presentation for students
Cell Structure & Organelles in detailed.
Pre independence Education in Inndia.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Basic Mud Logging Guide for educational purpose
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...

Stack Operations

  • 2. STACK  Stack is a data structure in which last item inserted is taken out first  It works in LIFO manner (last in first out) 2MADE BY RIDA ZAMAN
  • 3. OPERATIONS ON STACK  We can perform two operation on a stack  INSERTION (PUSH)  DELETION (POP) 3MADE BY RIDA ZAMAN
  • 4. STACK ORGANIZATION IN STACK ORGANIZATION WE STORE OR PLACE OUR DATA IN A MANNER OF A STACK. 4MADE BY RIDA ZAMAN
  • 5. STACK POINTER  It’s an register which is used to store the address of the top item in the stack  It’s a 6-bit register 5MADE BY RIDA ZAMAN
  • 6. DATA REGISTER Whatever value we INSERT(PUSH) or DELETE(POP) from the stack it stores in data register It’s a 2byte register /16bits 6MADE BY RIDA ZAMAN
  • 7. TYPES OF STACK ORGANIZATION There are two types of stack organization we have for our CPU  REGISTER STACK  MEMORY STACK 7MADE BY RIDA ZAMAN
  • 8. REGISTER STACK  If we have for example finite number of words which we want to insert at top of another and making stack out of it through register stack. 8MADE BY RIDA ZAMAN
  • 9. SINGLE BIT REGISTER We have two single bit registers  FULL: If the entire stack is full then this full register will set to be 1  EMPTY: If the entire stack is empty then this empty register will set to be 1 9MADE BY RIDA ZAMAN
  • 10. ALGORITHM FOR PUSH  SPSP+1  M{SP}DR  IF(SP=0)THEN (F1)  EMPTY0 10MADE BY RIDA ZAMAN
  • 11. ALGORITHM FOR PUSH STEP BY STEP  SPSP+1 Increment stack by a value 1  M{SP}DR Whatever content present in data register place it inside the memory word to which stack pointer is presently pointing  IF(SP=0)THEN (F1) We are performing push operation so we may encounter a position where our stack would become full so we have to set our full bit to 1  If our stack pointer is equal to zero set full=1  EMPTY0 Because we are putting values into the stack so its not empty anymore 11MADE BY RIDA ZAMAN
  • 12. ALGORITHM FOR POP  DRM{SP}  SPSP-1  IF {SP=0}{EMPTY1}  FULL0 12MADE BY RIDA ZAMAN
  • 13. ALGORITHM FOR POP STEP BY STEP  DRM{SP}Whatever content I have in the memory word that the stack pointer is pointing at present store it in the data register  SPSP-1 The stack pointer should point to the next top element ,it must be decremented by a value-1  IF{SP=0}{EMPTY1} We are performing POP operation so we may encounter a position where our stack would become entirely empty at that point we will set empty =1  FULL0 Because we are deleting values from stack so its obvious that it wont become full at any point 13MADE BY RIDA ZAMAN
  • 14. MEMORY STACK  In Memory stack we have a Memory Unit  In memory unit we divide memory into 3 portions  PROGRAM(INSTRUSTIONS): it is use to access/fetch instructions from memory  DATA(OPERANDS): it is use to access/fetch data and operands from memory  STACK: it is use to push or pop item into the stack  In memory stack our stack grows with decreasing address  There is different algorithm for both memory and register stacks 14MADE BY RIDA ZAMAN
  • 15. MEMORY UNIT 15MADE BY RIDA ZAMAN
  • 17. ALGORITHM FOR PUSH STEP BY STEP  SPSP-1 The first operation we will do is we will decrement our stack pointer  M{SP}DR Whatever data we have in the data register we should place it at the memory word at which the stack pointer is pointing at 17MADE BY RIDA ZAMAN
  • 18. ALGORITHM FOR POP STEP BY STEP  DRM{SP} Whatever content I have in the memory word of stack pointer I have to place it into data register  SPSP+1 Then we’ll increment our stack pointer by 1 18MADE BY RIDA ZAMAN
  • 19. DIFFERENCE BETWEEN REGISTER STACK AND MEMORY STACK  The stack grows with increasing address in register stack  Register stack is generally on the CPU  Access to register stack is fast  Register stack is limited size wise  The stack grows with decreasing address in register stack  Memory stack is on the RAM(main memory)  Access to memory stack is not as fast as register stack  Memory stack is larger then register stack size wise 19MADE BY RIDA ZAMAN
  • 20. PRACTICAL APPLICATION OF HOW STACK ORGANIZATION WORKS INSIDE OUR CENTRAL PROCESSING UNIT 20MADE BY RIDA ZAMAN
  • 21. DIFFERENT NOTATIONS WE HAVE IN REPRESENTING ARITHMETIC NOTATIONS  INFIX  PREFIX (POLISH NOTATION)  POSTFIX (REVERSE POLISH NOTATION/RPN) 21MADE BY RIDA ZAMAN
  • 22. INFIX NOTATION  In INFIX notation we have to write the operator in between the operands 22MADE BY RIDA ZAMAN
  • 23. PREFIX NOTATION  In PREFIX notation we have to write the operator before the operands  Most of the computer use PREFIX notation to execute arithmetic operations 23MADE BY RIDA ZAMAN
  • 24. POSTFIX (REVERSE POLISH NOTATION/RPN)  In POSTFIX notation we have to write the operator after the operands 24MADE BY RIDA ZAMAN
  • 26. SO WHAT THE COMPUTER DOES?  It scan the particular expression from left to right whenever it encounters an operator it does the particular operation on the previous two elements/operands that are scanning 26MADE BY RIDA ZAMAN
  • 27. HOW STACK ORGANIZATION IS USE TO EVALUATE ARITHEMATIC EXPRESSIONS 27MADE BY RIDA ZAMAN
  • 28. WHEN AN OPERATOR IS ENCOUNTERED  The two top most elements in the stack are use for the operation  The stack is popped and the result of the operation replaces the lower operand 28MADE BY RIDA ZAMAN
  • 30. 30MADE BY RIDA ZAMAN