Featured Post

Wednesday, October 5, 2016

Role of Stack in Computer Organization




         A stack is a data structure where we can store a group of items. Elements are added and removed from the top of the stack. i.e., the element to be removed is top of the stack. Stack follows Last In First Out(LIFO) order in adding and deleting the elements. Adding an element is called push operation and removing the element is called pop operation.

Consider a scenario like:
                 
                           Main memory capacity is 2048 MB. Stack occupies memory location from 2000 to 1500 location. Initially the stack is empty . Lets have a stack pointer whose name is SP to point the elements in the stack.

Note: When we are adding elements to a stack the stack moves towards lower memory locations i.e., stack moves form location 2000 to 1500.

push operation:
   
                         Adding an element to a stack is called push operation. When adding an element to a stack we need to decrement the stack pointer SP. Then after decrementing the stack the element to be pushed on to the new location pointer to by stack pointer SP.



For example we want to place a data item A on to stack.

                                    SP=SP-1
                                    MOVE A,[SP]


Note: [SP]  stands for value at address pointed to by SP

The above assembly language instructions can be written in a single instruction like

                                     MOVE A,-[SP]          

Now SP is pointing to new data item A

POP Operation:  

                       Removing an element from the stack is called pop operation. Removing an element means we are not physically removing the item from the stack but we just incrementing the stack pointer to show the next top element. To implement pop operation first we need to copy the item and then just increment the stack pointer.

                                            MOVE [SP],TEMP
                                            SP=SP+1

The above assembly language instruction can be written in a single instruction as


                                MOVE [SP]+,TEMP

Now the Stack pointer SP is pointing to next top element and removed element is in TEMP variable.





role of stack and queue in computer organisation, push and pop operation in CO, STACKFULL, STACK EMPTY, branch routines, rotate instructions, shift instructions arithmetic instructions, instruction and instruction sequencing. addressing modes, machine instructions. logic instructions, machine instructions. buses, DMA, generation of computers, data bus, control bus, address bus, 

                         












No comments:

Post a Comment