SUBMITTED BY
S.Nandhin
N.S COLLEGE OF ARTS & SCIENC
STACK INTRODUCTION
 What is stack ?
 Stack with example
 Push and Pop
 Difference Push and Pop
 Stack register
STACK
 The stack is a temporary store data and address
 The CPU may PUSH important data on to the stack
 While it is processing other data
What is Stack?
 The stack is a LIFO->LAST IN FIRST OUT
TOP
BOTTOM
5
4
3
2
1
STACK Pointer
STACK
 These are important instructions that store and retrieve
data the LIFO stack memory
 They Two main functions:
PUSH
POP
PUSH: Add item to top
POP: Remove item from top
STACK EXAMPLE
STACK IS
EMPTY
7
PUSH 7 PUSH 8
7
8
STACK Example
EMPTY
STACK
7
POP 8 POP 7
STACK INSTRUCTION
NAME
MNEMONICS AND
FORMAT DESCRIPTION
Push onto the stack PUSH SRC (SP) (SP)-2
((SP)+1: (sp))
(SRC)
Pop from the stack POP DST (DST) ((SP)+1:
(SP))
(SP) (SP)+2
Push the flags PUSHF (SP) (SP)-2
((SP)+1 : (SP))
(PSW)
Pop the flags POPF (PSW) ((SP)+1 :
(SP))
(SP) (SP)+2
PUSH & POP Definition
 These are important instruction that store and retrieve data the
LIFO Stack memory
 There are SIX Frames of the PUSH and POP
 Instruction,register,memory,immediate,segment register ,flags and all
register
 PUSH: Push op code copies data from the source address to stack.
 POP: Pop op code copies data from the stack to the destination address.
PUSH and POP example
Difference between PUSH &
POP Key Difference push is when an Entry is“PUSHED “ on to the Stack
 Pop is when the last pushed Entry is “Popped off” the stack
 PUSH & POP FOR EXAMPLE:
 PUSH CX
 PUSH DX
 POP DX
 POP CX
STACK REGISTER
o In 8086 main stack register is called Stack pointer (SP)
o The Stack segment register (SS) is usually used to store
information about memory segment
o That stores the call stack of currently Executed
program SP points to current Stack Top.
Setting up a Stack by Loading the SS and
Sp register
STACK_SEG EGMENT
DW 30 DUP(?)
TOS LABEL WORD
STACK_SEG ENDS
CODE_SEG SEGMENT
ASSUME CS:CODE SEG, SS:STACK SEG
START : MOV AX,STACK_SEG
MOV SS,AX ;INITIALIZES SS
MOV SP,OFFSET TOS ;INITIALIZES SP
:
:
CODE_SEG ENDS
Stack

Stack

  • 1.
  • 2.
    STACK INTRODUCTION  Whatis stack ?  Stack with example  Push and Pop  Difference Push and Pop  Stack register
  • 3.
    STACK  The stackis a temporary store data and address  The CPU may PUSH important data on to the stack  While it is processing other data
  • 4.
    What is Stack? The stack is a LIFO->LAST IN FIRST OUT TOP BOTTOM 5 4 3 2 1 STACK Pointer
  • 5.
    STACK  These areimportant instructions that store and retrieve data the LIFO stack memory  They Two main functions: PUSH POP PUSH: Add item to top POP: Remove item from top
  • 6.
  • 7.
  • 8.
    STACK INSTRUCTION NAME MNEMONICS AND FORMATDESCRIPTION Push onto the stack PUSH SRC (SP) (SP)-2 ((SP)+1: (sp)) (SRC) Pop from the stack POP DST (DST) ((SP)+1: (SP)) (SP) (SP)+2 Push the flags PUSHF (SP) (SP)-2 ((SP)+1 : (SP)) (PSW) Pop the flags POPF (PSW) ((SP)+1 : (SP)) (SP) (SP)+2
  • 9.
    PUSH & POPDefinition  These are important instruction that store and retrieve data the LIFO Stack memory  There are SIX Frames of the PUSH and POP  Instruction,register,memory,immediate,segment register ,flags and all register  PUSH: Push op code copies data from the source address to stack.  POP: Pop op code copies data from the stack to the destination address.
  • 10.
    PUSH and POPexample
  • 11.
    Difference between PUSH& POP Key Difference push is when an Entry is“PUSHED “ on to the Stack  Pop is when the last pushed Entry is “Popped off” the stack  PUSH & POP FOR EXAMPLE:  PUSH CX  PUSH DX  POP DX  POP CX
  • 12.
    STACK REGISTER o In8086 main stack register is called Stack pointer (SP) o The Stack segment register (SS) is usually used to store information about memory segment o That stores the call stack of currently Executed program SP points to current Stack Top.
  • 13.
    Setting up aStack by Loading the SS and Sp register STACK_SEG EGMENT DW 30 DUP(?) TOS LABEL WORD STACK_SEG ENDS CODE_SEG SEGMENT ASSUME CS:CODE SEG, SS:STACK SEG START : MOV AX,STACK_SEG MOV SS,AX ;INITIALIZES SS MOV SP,OFFSET TOS ;INITIALIZES SP : : CODE_SEG ENDS