4. 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
7. 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
8. 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.
9. 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.
10. 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].