Push vs. Pop Statements: Understanding Stack Operations

This page explains the difference between the push statement and the pop statement. Both statements are related to the stack data structure.

They are typically used when an ISR (Interrupt Service Routine/function) is called within a program.

When an ISR is called, the push statement stores variables onto the stack memory segment. This essentially saves the current state of the program.

When the Program Counter (PC) returns control from the ISR back to the main program, the pop statement retrieves the variables from the top of the stack. This restores the program to the state it was in before the interrupt. This behavior is why the stack is also called LIFO (Last In First Out).

The push statement usually takes two arguments:

  1. The stack address.
  2. The variable to be stored on the stack.

The pop statement, on the other hand, typically takes only one argument:

  1. The stack address.

In Summary:

  • Push: Saves data onto the stack.
  • Pop: Retrieves data from the stack.