Stack Organization
Computer Organization | Stack based CPU Organization
STACK ORGANIZATION. Stack is a storage structure that stores information in such a way that the last item stored is the first item retrieved. It is based on the principle of LIFO (Last-in-first-out). The stackin digital computers is a group of memory locations with a register that holds the address of top of element.
The computers which use Stack-based CPU Organization are based on a data structure called stack. The stack is a list of data words. 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). In this organisation, ALU operations are performed on stack data. It means both the operands are always required on the stack. After manipulation, the result is placed in the stack.
The main two operations that are performed on the operators of the stack are Push and Pop. These two operations are performed from one end only.
- Push –
This operation results in inserting one operand at the top of the stack and it decrease the stack pointer register. The format of the PUSH instruction is:PUSH
It inserts the data word at specified address to the top of the stack. It can be implemented as://decrement SP by 1 SP <-- SP - 1 //store the content of specified memory address //into SP; i.e, at top of stack SP <-- (memory address)
- Pop –
This operation results in deleting one operand from the top of the stack and it increase the stack pointer register. The format of the POP instruction is:
POP
It deletes the data word at the top of the stack to the specified address. It can be implemented as:
//transfer the content of SP (i.e, at top most data) //into specified memory location (memory address) <-- SP //increment SP by 1 SP <-- SP + 1
Operation type instruction does not need the address field in this CPU organization. This is because the operation is performed on the two operands that are on the top of the stack. For example:
SUB
This instruction contains the opcode only with no address field. It pops the two top data from the stack, subtracting the data, and pushing the result into the stack at the top.
PDP-11, Intel’s 8085 and HP 3000 are some of the examples of the stack organized computers.
The advantages of Stack based CPU organization –
- Efficient computation of complex arithmetic expressions.
- Execution of instructions is fast because operand data are stored in consecutive memory locations.
- Length of instruction is short as they do not have address field.
The disadvantages of Stack based CPU organization –
- The size of the program increases.
Note:Stack based CPU organisation uses zero address instruction.
The Stack Data Structure
A stack is a LIFO (last-in, first-out) list. There are exactly two operations that can be performed on a stack.
Diagram of a stack
- A push operation adds a new item to the top of the stack.
- A pop operation removes an item from the top of the stack.
// sp points to next available element on the stack // sp is initialized to 0 int push(int stack[], int sp, int value) { if ( sp == STACK_SIZE ) return STACK_FULL; else stack[sp++] = value; return SUCCESS; } int pop(int stack[], int sp) { if ( sp == 0 ) return STACK_EMPTY; else return stack[--sp]; }
Comments
Post a Comment