STACK
ORGANISATION
Submitted by: Shivam Shrivastav
Roll no: 220150800054
Submitted to: MANDEEP SIR
 Stack: A storage device that stores
information in such a manner that the item
stored last is the first item retrieved.
 Stack is also called last-in first-out(LIFO).
it works on a LIFO principal.
STACK ORGANISATION
STACK ORGANISATION
Stack pointer: A register that holds the
address of the top item in the stack.
SP always points at the top item in the stack.
Stack Operations: The two operations are
 Push: It is used to insert an item into the stack.
 Pop: it is used to retrieve an item into the
stack.
IMPLEMENTATION OF STACK
In computer stack can be implemented
in two ways---
 Register stack
 Memory stack
 A stack is a collection of
registers storing temporary
information.
REGISTER STACK
A
FULL EMPTY
SP
B
C
DR
address
0
1
2
3
4
63
 In a 64-word stack, the stack
pointer contains 6 bits.
 The one-bit register is full is
set to 1 when the stack is
full.
 Empty register is 1 when the
stack is empty.
 The data registers(DR) hold
the data to be written into or
read from the stack.
STACK OPERATIONS
 PUSH OPERATIONS: The process of putting
a new element into the stack is known as
PUSH Operations.
• Step 1: Check if the stack is full.
• Step 2: If the stack is full, produce an error and
exit.
• Step 3: If the stack is not full, increment top to
point next space.
• Step 4: Add data element to stack location,
where the top is pointing.
• Step 5: Return success.
TOP
TOP
E
STACK OPERATIONS
 Pop Operations: Accessing the content while
removing it from the stack is known as a Pop
Operations
• Step 1:Checks if the stack is empty.
• Step 2:If the stack is empty, produce an error and
exit.
• Step 3:If the stack is not empty, access the data
elements at which the top is pointing.
• Step 4:Decreases the value of the top by 1.
• Step 5:Return success.
D
C
B
A
C
B
A
TOP
D
STACK OPERATIONS
REVERSE POLISH NOTATION(Postfix)
• A stack organization is very effective for evaluating arithmetic operations.
• A * B + C * D (AB*)+(CD*) = AB*CD*+
• (3 * 4 + 5 * 6 = (34*56*+)
• First convert the arithmetic expression into the equal to Polish
notation.
• PUSH the operands into the stack in the order in which they
appear.
• Finally only the results of the operation is left on the stack top.
STACK OPERATIONS
EVALUATING PROCEDURE:
• Scan the expression from left to right.
• When an operator is reached perform the operation with the
• operands found on the left side of the operator.
• Replace the two operands and the operator by the result
obtained from the operation.
(example)
Infix 3 * 4 + 5 * 6 = 42
Postfix 3 4 * 5 6 * +
12 5 6 * +
12 30 +
42
STACK OPERATION
REVERSE POLISH NOTATION
• Reverse polish notation evaluation with a stack.
• Stack is the most efficient way for evaluating arithmetic
operations.
Stack evaluation:
Get value
If the value is data: push the
data
Else if the value is operation:
Pop, pop evaluate and push
STACK OPERATION
REVERSE POLISH NOTATION
Example using stack to do this :
3 * 4 + 5 * 6 = 42
3 4 * 5 6 * +
SP
3
3
input
4
3
4
12
*
5
12
5
6
5
12
6
30
12
*
42
*
THANK YOU

stack.pptx stack overflow in computer organisations

  • 1.
    STACK ORGANISATION Submitted by: ShivamShrivastav Roll no: 220150800054 Submitted to: MANDEEP SIR
  • 2.
     Stack: Astorage device that stores information in such a manner that the item stored last is the first item retrieved.  Stack is also called last-in first-out(LIFO). it works on a LIFO principal. STACK ORGANISATION
  • 3.
    STACK ORGANISATION Stack pointer:A register that holds the address of the top item in the stack. SP always points at the top item in the stack. Stack Operations: The two operations are  Push: It is used to insert an item into the stack.  Pop: it is used to retrieve an item into the stack.
  • 4.
    IMPLEMENTATION OF STACK Incomputer stack can be implemented in two ways---  Register stack  Memory stack
  • 5.
     A stackis a collection of registers storing temporary information. REGISTER STACK A FULL EMPTY SP B C DR address 0 1 2 3 4 63  In a 64-word stack, the stack pointer contains 6 bits.  The one-bit register is full is set to 1 when the stack is full.  Empty register is 1 when the stack is empty.  The data registers(DR) hold the data to be written into or read from the stack.
  • 6.
    STACK OPERATIONS  PUSHOPERATIONS: The process of putting a new element into the stack is known as PUSH Operations. • Step 1: Check if the stack is full. • Step 2: If the stack is full, produce an error and exit. • Step 3: If the stack is not full, increment top to point next space. • Step 4: Add data element to stack location, where the top is pointing. • Step 5: Return success. TOP TOP E
  • 7.
    STACK OPERATIONS  PopOperations: Accessing the content while removing it from the stack is known as a Pop Operations • Step 1:Checks if the stack is empty. • Step 2:If the stack is empty, produce an error and exit. • Step 3:If the stack is not empty, access the data elements at which the top is pointing. • Step 4:Decreases the value of the top by 1. • Step 5:Return success. D C B A C B A TOP D
  • 8.
    STACK OPERATIONS REVERSE POLISHNOTATION(Postfix) • A stack organization is very effective for evaluating arithmetic operations. • A * B + C * D (AB*)+(CD*) = AB*CD*+ • (3 * 4 + 5 * 6 = (34*56*+) • First convert the arithmetic expression into the equal to Polish notation. • PUSH the operands into the stack in the order in which they appear. • Finally only the results of the operation is left on the stack top.
  • 9.
    STACK OPERATIONS EVALUATING PROCEDURE: •Scan the expression from left to right. • When an operator is reached perform the operation with the • operands found on the left side of the operator. • Replace the two operands and the operator by the result obtained from the operation. (example) Infix 3 * 4 + 5 * 6 = 42 Postfix 3 4 * 5 6 * + 12 5 6 * + 12 30 + 42
  • 10.
    STACK OPERATION REVERSE POLISHNOTATION • Reverse polish notation evaluation with a stack. • Stack is the most efficient way for evaluating arithmetic operations. Stack evaluation: Get value If the value is data: push the data Else if the value is operation: Pop, pop evaluate and push
  • 11.
    STACK OPERATION REVERSE POLISHNOTATION Example using stack to do this : 3 * 4 + 5 * 6 = 42 3 4 * 5 6 * + SP 3 3 input 4 3 4 12 * 5 12 5 6 5 12 6 30 12 * 42 *
  • 12.