LECTURER- COMPUTER SCIENCE & ENGINEERING, GOVT. POLYTECHNIC COLLEGE, JODHPUR ( RAJ. ) Stack in 8085 Microprocessor • The stack is a set of memory locations in RAM and used to store information temporarily during execution of program. • The stack is Last In First Out ( LIFO) structure. • The beginning of the stack (also known as Top of Stack) defined in main program using LXI SP, 16-bit memory address instruction which loads 16-bit memory address in stack pointer (SP) register. • Once Top of Stack is defined, information cab be added / removed only to/ from Top of Stack . • In stack information can be added using PUSH instruction and removed using POP instruction. • The stack grows upward in the decreasing order of memory addresses. Therefore Stack Pointer (SP) is initialized with highest available memory address of free memory space in order to prevent program being destroyed by stack information. • The size of stack is limited only by available memory space. • The microprocessor itself stores memory address in Program Counter (PC) in stack when a subroutine is called. Stack related instructions • In 8085 microprocessor, the stack related instructions are – LXI SP, PUSH, POP, and XTHL etc. All these instructions do not modify any flags. These instructions are described in following table: Mnemonics Operands Description LXI SP, 16-bit Loads 16-bit memory address in memory Stack Pointer (SP) register, in order address to define Top Of Stack(TOS). Three byte instruction and Immediate Addressing mode. Mnemonics Operands Description PUSH Rp or PSW Store register pair / Program Status Word on Stack. PSW consists of Accumulator and Flag register. This is one byte instruction and Register Indirect Addressing mode. Copies contents of specified register pair or PSW on stack in following steps: • Decrement Stack Pointer (SP) by one. • Copy contents of high order register into memory location pointed by SP. • Now again decrement Stack Pointer (SP) by one. • Finally copy contents of low order register into memory location pointed by SP. Mnemonics Operands Description POP Rp or PSW Pop off stack into register pair / Program Status Word. This is one byte instruction and Register Indirect Addressing mode. Copies contents of top two memory locations of stack into specified register pair or PSW in following steps: • Copy contents of memory location pointed by SP into low order register of register pair or PSW. • Increment Stack Pointer (SP) by one. • Now copy contents of memory location pointed by SP into high order register of register pair or PSW. • Finally again increment Stack Pointer (SP) by one. Mnemo Operands Description nics XTHL Exchange register pair HL with Top of Stack : One byte instruction. • The contents of register L are exchanged with top location of stack pointed by SP. • The contents of register H are exchanged with next location of stack pointed by (SP+1). • The contents of SP not changed.