|
Albert, >Now I'm curious. In my experience, a subroutine call involved saving the >current address (usually on a stack), branching to the subroutine, and >branching back to the saved address ( plus 1 instruction) at the end of the >subroutine. If RPG doesn't do it this way, how does it do it? (Disclaimer: I don't work for IBM; this is just my observations on what RPG does.) It does save the address, but not with push/pop operations on a stack the way most languages do. It in essence can save one address per subroutine. It just stores the address, and when (or if) you reach the ENDSR it branches to the address stored. Since nothing was put on a stack, if you branch out of the subroutine (via GOTO or *PSSR) prior to reaching the ENDSR, nothing is left unbalanced. Since there is only one return addresss storable per subroutine, RPG cannot let you perform recursion (except now with subprocedures). This helps explain this admonition from the RPG reference manual: "An EXSR or CASxx specification within a subroutine cannot directly call itself. Indirect calls to itself through another subroutine should not be performed, because unpredictable results will occur." Also: "A GOTO within a subroutine in the main procedure can be issued to a TAG within the same subroutine, detail calculations or total calculations." Having the *PSSR branch back to *DETC (or another spot in the cycle) is somewhat like performing a GOTO from with the subroutine -- it just never reaches the ENDSR to branch back to the calling address. The next time the subroutine is called, its caller's address overlays the previous return address, but the stack remains balanced. Or at least, that is my understanding of what RPG is doing... Doug +--- | This is the Midrange System Mailing List! | To submit a new message, send your mail to MIDRANGE-L@midrange.com. | To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com. | To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.