KCS302 - Stack Organization & RPN
KCS302 - Stack Organization & RPN
Architecture
Unit-I
• Stack Organization: Introduction
• Register Stack
• Memory Stack
Stack Organization: Introduction
• A stack is a storage device that stores
information in such a manner that the element
stored last is the first element retrieved.
• The top element is read from the stack into DR. The stack
pointer is then decremented. If its value reaches zero, the
stack is empty, so EMTY is set to 1.
• This condition is reached if the element read was in
location 1. Once this element is read out, SP is decremented
and reaches the value 0, which is the initial value of SP.
Memory Stack
Memory Stack: Description
In the diagram, three registers are connected to a common address
bus and either one can provide an address for memory:
As shown, the initial value of SP can be 4001 and the stack grows
with decreasing addresses. Thus the first element stored in the
stack is at address 4000, the second element is stored at address
3999, and the last address that can be used for the stack is 3000.
Push & Pop Operations in Memory Stack
A new element is inserted with the push operation as follows:
SP ← SP – 1 Decrement stack pointer
M [SP] ← DR Write element on top of the stack
The top element is read from the stack into DR. The stack pointer
is then incremented to point at the next item in the stack.
Practice Set - 03
· Q1 (*MM8-5). Let SP = 000000 in the stack of Fig. 8-3. How
many elements are there in the stack if:
a. FULL = 1 and EMTY = 0?
b. FULL = 0 and EMTY = 1?