Difference between PUSH and POP

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
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
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
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

0 Comments