4.1 Saving and restoring register values

Push and pop are commonly used to save and restore the values of registers when they may be destroyed. Observe the following code:

pushl %eax 
pushl %ebx 
# do something that overwrites the value of eax and ebx 
popl  %ebx 
popl  %eax

Note how the order of the push and pop sequences are reversed. This is necessary because the last item pushed is the first item popped (in this case, ebx).