× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: RE: *PSSR subroutine and the call stack
  • From: david.kahn@xxxxxxxxxx
  • Date: Mon, 10 May 1999 16:05:24 +0100



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 thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.