free hit counter

Stack And Microprocessor

Date: 12 Apr 2013

What is stack?

Stack is a group of memory locations in the Read/Write memory. It is used for storage of binary information during the execution of a program. The beginning of the stack is defined in the program by using the instruction


This instruction loads a 16 bit memory address in the stack pointer register (SP) of the microprocessor. Once the SP is defined, storing of data bytes begins at the memory address that is one less than the address in the SP. The information is stored in reversed numerical order.

Data bytes in the register pair of the microprocessor can be stored in the stack in reversed order by using the instruction, RSH. Data bytes can be transferred from the stack to representative register by using the instruction, POP.

Since two data bytes are being stored at a time, the 16 bit memory address in the SP is decremented by 2. When data bytes are retrieved, the address is incremented by 2.

The stack is initialized at the highest available memory location to prevent the program from being removed by the stack information.

Stack Instruction

  1. To create the stack, initialize the SP register. This can be done by using the following instruction.

    LXI SP, 16 bit address

    This instruction loads SP register with the 16 bit address

  2. The following instruction inserts element into the stack.

    PUSH Rp

    where Rp stands for register pair. This instruction copies the content specified by the register pair into the stack.


    PUSH B
    PUSH D
    PUSH H

    When PUSH Rp is encountered the SP is decremented and the content of higher order register, B, D or H are copied in the locations shown by SP. The SP is again decremented and the lower order register content will be copied into the stack.

  3. To delete an element from the stack use the following instruction

    POP Rp

    It copies the content of top two memory locations of the stack into the specified register pair, Rp. First content of the memory location indicated by the SP is copied into the lower order register and then the SP is incremented by 1. Now this content is copied into higher order register. Stack instructions belong to data transfer group. Thus content of source are not affected and no flags are affected.


    POP B
    POP D
    POP H

  1. One Comments to “Stack And Microprocessor”

    1. […] stack is an array of registers organized in a last in first out manner. The top of the element is always […]