Stack is basically a linear type of data structructure that can store many values on continuous locations. The most peculiar thing about stacks is their access mode. The element added to the stack at very last will be the first to be accessed from it. Thus the element added to the stack at very first will be the last to be accessed. The access mode of this type is referred to as LIFO (Last In First Out). This kind of storage is somehow similar to the storage of bread slices in a packet.
Adding an element to the stack is called PUSH and accessing an element is called POP.
In a computer architecture, stacks are used in the following two ways:
In a very specific architecture where there is a set sequence of instructions to process, a memory stack can be used of set memory locations. The order of execution of these instructions is obviously LIFO.
In a conventional CPU, a stack of registers is always preferable because of the high speed operation. A memory stack will be a little slow when compared to a register stack. The register stack organization involves five integral components:
The SP points to the element on TOS (Top Of Stack). Consider the following diagram:
Since the SP points to the element on TOS, we first need to give an increment to the SP so that it points to the next register on stack. Now we transfer the contents of DR into the pointed register. The RTL notations are as under:
 To pop an element from stack, we first transfer the content of register (pointed by SP) to DR. Now we make a decrement to SP so that it points to the previous register on stack.