|
Pete Hall <pbhall@execpc.com> wrote: >Several years ago, I had a program that did something like this: > >mainline calls Sub A >Sub A calls Sub B >Sub B calls Sub C >Sub C calls Sub A >Sub A returns to mainline (not Sub C) - this was not the desired behavior > >From this experience, I surmise that subroutine returns are implemented as >branches to a program counter address which is set at the time the >subroutine is first invoked. This didn't seem right to me so I tested it using the following simple program. C EXSR A C MOVE *ON *INLR C A BEGSR C *IN30 IFEQ *OFF C MOVE *ON *IN30 C EXSR B C ENDIF C ENDSR C B BEGSR C EXSR C C ENDSR C C BEGSR C EXSR A C ENDSR When you run it you find mainline calls A, A calls B, B calls C, C calls A. A then ends and returns to C (not mainline). C returns to B, B returns to A, A returns to C and so on ad infinitum. It seems as though the return address is set when the subroutine is called, overwriting any previous return address. The ENDSR is therefore effectively a branch to the instruction following the last EXSR to have called the corresponding BEGSR. However, because the manual says the behaviour is unpredictable this could change from release to release. It simply depends how the compiler writer has implemented the EXSR rules. Dave Kahn, ABB Steward Ltd. +--- | 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.