Difference between PUSH and POP instruction

There is anomaly between hardware and software implementation of stack. In general when we PUSH data in the stack, the TOS (Top of Stack) is incremented) and it is decremented when we POP data from the stack. However in the real hardware i.e. memory stack is initialized from higher memory location i.e. TOS is decremented whenever data is pushed and it is TOS is incremented when data is popped. Following two examples with reference to PUSH and POP instruction of 8085 microprocessor illustrates that fact:

PUSH Instruction

PUSH  is used to store register pair data onto stack.

Syntax

PUSH Reg. pair

The contents of the register pair designated in the operand are copied onto the stack in the following sequence. The stack pointer register is decremented and the contents of the high order register (B, D, H, A) are copied into that location. The stack pointer register is decremented again and the contents of the low-order register (C, E, L, flags) are copied to that location.

Example: PUSH B

Suppose B contains 34 and C contains 56 and Top of Stack (i.e. SP) =2000

34 56

The PUSH B instruction makes the following changes in memory as shown and top of stack is decremented by 2.

i.e. Top Of Stack = SP – 2 = 2000 – 2 = 1998

 

Memory location Data
2000 34
1999 56
1998  

 

POP instruction

POP is used to extract data off stack and to store in register pair

Syntax

POP Reg. pair

The contents of the memory location pointed out by the stack pointer register are copied to the low-order register (C, E, L, status flags) of the operand. The stack pointer is incremented by 1 and the contents of that memory location are copied to the high-order register (B, D, H, A) of the operand. The stack pointer register is again incremented by 1.

Example: POP B

Suppose B contains 00 and C contains 00 and Stack pointer=1998

00 00

The POP B instruction makes the following changes in Register as shown and top of stack is incremented by 2.

I.e. new top of stack = SP + 2 = 1998 + 2 = 2000

34 56

 

Memory location Data
2000  
1999  
1998  

You may also like...