Previous Topic

Next Topic

Book Contents

Book Index

Subroutines: The subroutine stack

Subroutines are made possible by a mechanism called a subroutine stack. The subroutine stack is a "Last-in First-out" memory. This memory stores program memory addresses. When SPLatty executes a GoSub he notes where he is, and sticks the note on top of the stack, before jumping to the new place in the program. If inside that subroutine there is another Gosub, he again notes where he is, places that note on top of the previous one, and goes to the new place. When he encounters a Return he removes the top note off the stack of notes and goes to the place designated on the note. That way he can "unwind" the places he has to return to perfectly.

The stack of return addresses, the subroutine stack, can only contain a limited number of addresses. For dialects prior to dialect 12 the capacity is 4. From dialect 12 the capacity is 6.

Things you shouldn't do (with subroutines, that is)

Previous Topic

Next Topic