Slide 10.1: Laboratory IV: evaluating a Boolean expression with parentheses
Slide 10.3: PUSH and POP instructions
Home

The Runtime Stack


A stack is a data structure for storing items which are to be accessed in last-in first-out order. The operations on a stack are Error conditions are raised by attempting to pop an empty stack or to push an item onto a stack which has no room for further items (because of its implementation).

The runtime stack is a memory array managed directly by the CPU, and it is an essential part of the mechanism for calling and returning from procedures. The ESP (Extended Stack Pointer) register holds a 32-bit offset into some location on the stack. We rarely manipulate ESP directly; instead, it is indirectly modified by instructions such as CALL, RET, PUSH, and POP.

The following figures illustrate a series of stack operations:

 Initial Contents 
 Offset   Stack     
00001000 00000006 ESP
00000FFC    
00000FF8    
00000FF4    
00000FF0    
 PUSH 000000A5 
 Offset   Stack     
00001000 00000006  
00000FFC 000000A5 ESP
00000FF8    
00000FF4    
00000FF0    
 PUSH 00000010 
 Offset   Stack     
00001000 00000006  
00000FFC 000000A5  
00000FF8 00000010 ESP
00000FF4    
00000FF0    

 POP eax 
 Offset   Stack     
00001000 00000006  
00000FFC 000000A5 ESP
00000FF8    
00000FF4    
00000FF0    
 PUSH 000001AF 
 Offset   Stack     
00001000 00000006  
00000FFC 000000A5  
00000FF8 000001AF ESP
00000FF4    
00000FF0    
 POP eax 
 Offset   Stack     
00001000 00000006  
00000FFC 000000A5 ESP
00000FF8    
00000FF4    
00000FF0