Categories: Processor

Stack And Microprocessor

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

LXI SP

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.

    Examples

    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.

    Examples

    POP B
    POP D
    POP H

Robin

Share
Published by
Robin

Recent Posts

Hard Computing

What is hard computing? Hard computing is a traditional computing. It requires a precisely stated…

5 years ago

Soft Computing

Soft computing is a problem solving technology. It tends to fuse synergically different aspects of…

5 years ago

Cluster Computing

Cluster computing is an approach to achieve high performance, reliability or high throughput computing by…

5 years ago

Magnitude Comparator

Magnitude Comparator is a combinational circuit capable of comparing the relative magnitude of two binary…

10 years ago

Full-Subtractor

Full subtractor is a combinational circuit capable of performing subtraction on two bits namely minuend…

10 years ago

Half-Subtractor

Half-subtractor is a combinational circuit capable of subtracting a binary number from another binary number.…

10 years ago