CS-220, Week 7A
R. Eckert

NESTED PROCEDURES AND THE STACK

The following is an example of how the stack assures that the return
from a procedure always transfers control to the correct place.

                                   |   EXECUTION:
Offsets      Program               |   Action            IP    SP
-----------------------------      |   ------------------------------
        main    proc    far        |                    0000    020a
0000            ...                |   main is running  ....
                ...                |                    ....
                ...                |   call to a        0100
0100            call    a          |   0103 to stack    0103    0208
0103            ...                |                    0150
                ...                |   a is running     ....
014f            ret                |                    ....
        main    endp               |   call to b        0170
                                   |   0173 to stack    0173    0206
        a       proc    near       |                    0220
0150            ...                |   b is running     ....
                ...                |                    ....
0170            call    b          |   return from b    0230
0173            ...                |   0173 from stack  0231    0208
                ...                |                    0173
021f            ret                |   a is running     ....
        a       endp               |                    ....
                                   |   return from a    021f
        b       proc    near       |   0103 from stack  0220    020a
0220            ...                |                    0103
                ...                |   main is running  ....
0230            ret                |                    ....
        b       endp               |