Stack & parameters passing through
stack
Presented by:
Ashfaq Hussain (fa16-bcs-064)
MURAD ALI (Fa16-bcs-046)
saqlain raza (fa16-bcs-068)
Content:
 Stack
 Operations of stack
 Parameter passing through stack
 Accessing Parameter In Stack
 Example of Bubble Sort
Stack
Operations of stack are:
Push & Pop
The last element pushed is pop
out first
Push and pop operation is only
work at the top of the stack
The top of the stack is
contained in a SP register
The PUSH Instruction
The POP Instruction
Contd…
Physical address of the stack is obtained by the
SS:SP combination
Stack is use to save things and recover from it when
needed
A decrementing stack moves from higher addresses
to lower addresses as elements are added in it
while an incrementing stack moves from lower
addresses to higher addresses as elements are
Added
The processor 8051 has an incrementing stack and
8088 processor has decrementing stack
Parameter passing through stack
Why we using Stack instead of Registers?
 Due to the limited number of registers.
 Due to this, parameter passing by registers is not
expandable and generalizable.
 However this is the fastest mechanism available for passing
parameters and is used where speed is important.
Parameter passing through stack
Considering stack as an alternate way:
 whatever data is placed there, it stays there, and across
function calls as well.
 In bubble sort subroutine example we place both of these
array address and the count of elements
on the stack.
 The subroutine is invoked with its return address on top of
the stack and its parameters bellow it.
Accessing Parameter In Stack:
 When the bubble sort subroutine is called, the stack pointer is
pointing to the return address .
 SP(Stack pointer) also point to the top of stack, So we cannot
access parameter using SP.
 Mov bp,sp
 Now we can access all parameter,
 The Second parameter is at [bp+2]
 The first parameter is at [bp+4].
Example of Bubble Sort
Cont…..
Cont….
Main Point of Stack..
Stack and; parameters passing through stack

Stack and; parameters passing through stack

  • 1.
    Stack & parameterspassing through stack Presented by: Ashfaq Hussain (fa16-bcs-064) MURAD ALI (Fa16-bcs-046) saqlain raza (fa16-bcs-068)
  • 2.
    Content:  Stack  Operationsof stack  Parameter passing through stack  Accessing Parameter In Stack  Example of Bubble Sort
  • 3.
  • 4.
    Operations of stackare: Push & Pop The last element pushed is pop out first Push and pop operation is only work at the top of the stack The top of the stack is contained in a SP register
  • 5.
  • 6.
  • 7.
    Contd… Physical address ofthe stack is obtained by the SS:SP combination Stack is use to save things and recover from it when needed A decrementing stack moves from higher addresses to lower addresses as elements are added in it while an incrementing stack moves from lower addresses to higher addresses as elements are Added The processor 8051 has an incrementing stack and 8088 processor has decrementing stack
  • 8.
    Parameter passing throughstack Why we using Stack instead of Registers?  Due to the limited number of registers.  Due to this, parameter passing by registers is not expandable and generalizable.  However this is the fastest mechanism available for passing parameters and is used where speed is important.
  • 9.
    Parameter passing throughstack Considering stack as an alternate way:  whatever data is placed there, it stays there, and across function calls as well.  In bubble sort subroutine example we place both of these array address and the count of elements on the stack.  The subroutine is invoked with its return address on top of the stack and its parameters bellow it.
  • 10.
    Accessing Parameter InStack:  When the bubble sort subroutine is called, the stack pointer is pointing to the return address .  SP(Stack pointer) also point to the top of stack, So we cannot access parameter using SP.  Mov bp,sp  Now we can access all parameter,  The Second parameter is at [bp+2]  The first parameter is at [bp+4].
  • 11.
  • 12.
  • 13.
  • 14.