Lecture 19 Stack Organisation
Lecture 19 Stack Organisation
STACK ORGANISATION
A stack is an ordered linear list in which all insertions and deletions are made at one end, called
top. It uses Last In First Out (LIFO) access method which is the most popular access method in
most of the CPU.
A register is used to store the address of the topmost element of the stack which is known as
Stack pointer (SP) because its value always points at the top item in the stack.. In this
organisation, ALU operations are performed on stack data.
Figure 1 Stack
The main two operations that are performed on the operands of the stack are Push and Pop.
These two operations are performed from one end only.
● Push operation - The operation of inserting an item onto a stack is called push operation.
● Pop operation- The operation of deleting an item onto a stack is called pop operation.
Applications
● Evaluation of mathematical expressions using Reverse Polish Notation
● To reverse a word. A given word is pushed to stack - letter by letter - and then poped out
letters from the stack.
● An "undo" mechanism in text editors; this operation is accomplished by keeping all text
changes in a stack
● Backtracking. This is a process when it is required to access the most recent data element in a
series of elements.
● Language processing
● space for parameters and local variables is created internally using a stack.
● The compiler's syntax check for matching braces is implemented by using stack.
● Memory stack- It is a logical part of memory allocated as stack. The logically partitioned part
of RAM is used to implement stack.
Register stack-
DR
● Program- The logical part of RAM where programs are stored. The program section address
starts from 1000.
● Data - It is the logical part of RAM where data ( operands) are stored.The data section address
starts from 2000.
● Stack - It is the part of RAM used to implement stack. It's address starts from 3000 and
continues upto 4001.
It is not necessary that the sequence and address of each part is fixed. It is logically decided by the
manufacturer.
Program counter (PC) is used to point the program counter.
Data register is used to store data
Data is pointed by the address pointer or register.
There is also a stack pointer.l
Example :. (3 * 4) * ( 5 * 6 ). 3 4* 5 6* *
→ 6
4 → 5 5 → 30
→
3 3 → 12 12 12 12 → 360
Actually, this is how a computer evaluates the mathematical expressions. It is one of the applications
of stack.