0% found this document useful (0 votes)
21 views

CPU-Stack organization

CSA notes

Uploaded by

mm88crhh2v
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

CPU-Stack organization

CSA notes

Uploaded by

mm88crhh2v
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Stack Organization

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 Ou t (LIFO) access method which is
the most popular access method in most of the C P U s .
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.

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 popped 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.

There are two types of stack organization which are used in the computer
hardware:

 Register stack: It is built using register


 Memory stack: It is logical part of memory allocated as stack. The
logically partitioned part of RAM is used to implement stack.

Register stack:

As shown in fig 2, there are 64 registers used to make a register stack. The
numbers 0,1,2,3,…..upto 63 denote the address of different registers.

 S P is a pointer which points to the top of the stack i.e. it currently points
to the item at the top.
 The two more registers called F LAG and EMPTY are used. These are
made up of flip-flops. It indicates whether the stack is full or not.
o If FULL = 1, then EMPTY = 0  stack is full.
o If FULL= 0, then EMPTY =1  stack is empty.
 D R is the data register through which data is transferred to and from the
stack.

Zero address instructions are used in registers stack organization i.e. the
address that does not contain the address of the operands.
In 64-word stack, the stack pointer contains 6 bits because 2 6 =64.

Since, S P has only 6 bits, it cannot exceed a number greater than 63(111111 in
binary). When 63 is incremented by 1 the result is 0 since 111111+1=1000000,
but S P can accommodate only the six least significant bits  S P points to
000000 address register which implies stack is full.

The P U S H operation is implemented with the following sequence of


microoperations:

S P  SP+1 Increment stack pointer


M[SP]  D R Write item on top of the stack
If (SP=0) then (FULL1) Check if stack is full
EMTY0 Mark the stack not empty

 The stack pointer is incremented so that it points to the address of


the next higher word.
 A memory write operation inserts the word from D R into the top of the
stack.
o S P holds the address of the top of the stack and that M[SP]
denotes the memory word specified by the address presently
available in S P.
 The first item stored in the stack is at address 1. The last item is stored
at address 0.
 If S P reaches 0  stack is full of items, so full is set to 1.
 If an item is written in the stack, obviously the stack cannot be empty, so
EMTY is cleared to 0.

A new item is deleted from the stack if the stack is not empty (if EMTY=0).
The POP operation consists of following sequence of microoperations:

D R M[SP] Read item from the top of the stack


SPSP-1 Decrement stack pointer
If(SP=0) then (EMTY1) Check if stack is empty
FULL 0 Mark the stack not full

 The top item is read from the stack into D R .


 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 item read was in location 1.
Memory Stack: The RAM is divided into three logical parts:
 Program: The logical part of RAM where programs are stored.
 Data: It is the logical part of the RAM where data(operands) are stored.
 Stack: It is the part of RAM used to implement stack.

Data register is used to store data. Data is pointed by the address pointer or
register. Program Counter (PC) is used to point the program instruction.

As shown in the diagram, the initial value of S P is 4001 and the stack grows
with decreasing addresses.

A new item is inserted with the P U S H operation as

follows: SP S P - 1

M[SP]  D R

A new item is deleted with a POP operation as follows:

DRM[SP]

SPSP + 1

You might also like