Stack and Subroutine
Stack and Subroutine
There are two methods to add data to the stack: Direct method and
Indirect method
Direct method
In the direct method, the stack pointers address is loaded into the
stack pointer register directly.
LXI SP,8000H
LXI H,1234H
PUSH H
POP D
HLT
Indirect method
In the indirect method, the stack pointers address is loaded into the
stack pointer register via another register pair.
LXI H,8000H
SPHL
LXI H,1234H
PUSH H
POP D
HLT
After the completion of the subroutine, the main program begins from
the instruction immediately following the CALL instruction.
The 8085 recognizes one additional register pair called the PSW
(Program Status Word).
– This register pair is made up of the Accumulator and the Flags
registers.
It is possible to push the PSW onto the stack, do whatever operations
are needed, then POP it off of the stack.
– The result is that the contents of the Accumulator and the status of
the Flags are returned to what they were before the operations were
executed.