Stack is a group of memory location 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 define in the program by using the instruction .
LXI SP
This instruction loads a 16 bit memory address in stack pointer register (SP) of the microprocessor. Once the SP is defined , storing of the data bites begins at the memory address that is one less than the address in the SP. The information is stored in reversed numeric 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 form 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.
LXI SP
This instruction loads a 16 bit memory address in stack pointer register (SP) of the microprocessor. Once the SP is defined , storing of the data bites begins at the memory address that is one less than the address in the SP. The information is stored in reversed numeric 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 form 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 :
- 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 16bit address
- The following instruction insert element into the stack.
Where Rp stands for register pair. The instruction copies the contents specified by the register pair into the stack.
Example :
PUSH B
PUSH D
PUSH H
When PUSH Rp is encounter the SP is decremented and the content of higher order register, B,D or H are copied in the location shown by SP. The SP is again decremented and the lower order register content will be copied into the stack.
- To delete an element from the stack using the following instruction
POP Rp
It copies the content of the top two memory location 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 the SP is incremented by 1. Now this Content is copied into the higher order register. Stack instruction belong to data transfer group, Thus content of source are not effected and no flags are effected.
Example:
POP B
POP D
POP H
No comments:
Post a Comment