Review: the stack data structure
 

A stack is a data structure with the following two operations:

  • void Push(int x):

      • Inserts the value "x" into the stack.       

    The value "x" is put "at the top" of the stack.


  • int Pop():

      • Remove the top value from the stack.

        The value removed is returned by the pop( ) operation.

Example push( ) operation
 

Suppose the stack is:


    Stack:






          Stack Top ---> +----------+
			 |    9     |  
                         +----------+
			 |    4     |
                         +----------+
   

 

Example push( ) operation
 

After a push(1) operation, the stack is:


    Stack:




          Stack Top ---> +----------+
                         |    1     |
                         +----------+
			 |    9     |  
                         +----------+
			 |    4     |
                         +----------+
   

 

Example pop( ) operation
 

Suppose the stack is:


    Stack:




          
                        
          Stack Top ---> +----------+
	     		 |    9     |  
                         +----------+
			 |    4     |
                         +----------+
   

 

Example pop( ) operation
 

After a pop( ) operation, the stack is:


    Stack:






  
		
          Stack Top ---> +----------+
			 |    4     |
                         +----------+
   

The pop( ) operation will return the value 9

The program runtime stack

Initial state when a program starts running:

  • All memory except the memory used by: (1) instructions and (2) permanent variables are available:

The program runtime stack

Some of the available memory is used maintains a program runtime stack to store runtime information:

  • The return addresses are stored in this program runtime stack !!!

Implementing the program runtime stack

The runtime stack is stored at the end of the memory:

The top of the stack is stored/recorded in the Stack Pointer Register SP:

The program (runtime) stack in EGTAPI
 

How do you find the program (runtime) stack in EGTAPI:

  • The SP register contains the top of the runtime stack

  • The content of the runtime stack is displayed in the System Stack window

Example: