I am looking for documentation/examples of how to nest multiple layers of subroutines in DOS/VS ASM.
I can do one-nesting, but if I try to nest two levels
main -> sub1 -> sub2 -> sub1 -> main
the system seems to hang or loop.? Trying to figure it out for an app that I am writing.
Cheers tom c
|
[...] main -> sub1 -> sub2 -> sub1 -> main How do you have your subroutine linkage designed? Simple saving of return register? If so, then that's your problem. Sub1 saves its return to main, but as soon as sub2 then calls sub1, sub1 saves its return to sub2, wiping out (overlaying/destroying) its previously saved return to main. End result is when sub2 returns back to ITS caller (sub1), sub1 then ends up returning back to sub2 again, not main. You need to use some type of "stack" approach. You need to maintain some type of "nesting level" value that is incremented upon entry and decremented upon exit, which is used to index into an array of return addresses (i.e. the "stack") so you can return back to the correct caller depending on the nesting level. -- "Fish" (David B. Trout) Software Development Laboratories mail: fish@...
|
Fish, Thank you for comments.? You confirmed what I thought was the issue. Looking through the fish-macros, I noticed you have a modified save macro.? Should I be using that version?
I have written a test program that nest three levels.? Level one and Level two work then it fails.? I am using the SAVE , CALL, and RETURN macros.
I think it is a matter of getting the saving of R13 correctly and use of the correct save area for each subroutine.
Thank you for your help.
Cheers /tom c
|
Hi Tom,
Typically 360/370 subroutine calls are done with a what is called a save area. This is 18 words allocated within the subroutine. On entry the registers are saved into the previous routines save area. Then the base register is set up and the save pointer is pointed to the current save area. On exit the registers are restore, this will include the previous save area.
This means that if you call a subroutine again it will wipe out the previous calls information. To do this properly you will either need to allocate a bunch of memory to save all the registers in and advance the save pointer for each call. The other option is to allocate and free save areas at each call.
Basically you will need to implement some sort of stack to handle function calls if you want true recursive calls.
Rich
|
Richard,
Thank you for the info.? I need to figure out how to implement your suggestion.? I found in the documentation on SAVE an option ?????????? SAVE? (14,12),,xxxxxxx where xxxx is a ds 18f area to save the regs.? I am trying to figure out if the change will work on DOS/VS rel 34.
Cheers /tom c
toggle quoted message
Show quoted text
On Wed, Oct 12, 2022 at 9:59 AM Richard Cornwell < rich@...> wrote: Hi Tom,
? ?Typically 360/370 subroutine calls are done with a what is called a
?save area. This is 18 words allocated within the subroutine. On entry
?the registers are saved into the previous routines save area. Then the
?base register is set up and the save pointer is pointed to the current
?save area. On exit the registers are restore, this will include the
?previous save area.
?This means that if you call a subroutine again it will wipe out the
?previous calls information. To do this properly you will either need to
?allocate a bunch of memory to save all the registers in and advance the
?save pointer for each call. The other option is to allocate and free
?save areas at each call.
?Basically you will need to implement some sort of stack to handle
?function calls if you want true recursive calls.
Rich
|
Hi Tom,
You are going to have to implement your own routines. Perhaps check out how Algol or PL/1 handle subroutine calls. But standard call routines do not support re-entrant calls.
Rich
toggle quoted message
Show quoted text
Thank you for the info. I need to figure out how to implement your suggestion. I found in the documentation on SAVE an option SAVE (14,12),,xxxxxxx where xxxx is a ds 18f area to save the regs. I am trying to figure out if the change will work on DOS/VS rel 34.
Cheers /tom c
On Wed, Oct 12, 2022 at 9:59 AM Richard Cornwell <rich@...> wrote:
Hi Tom,
Typically 360/370 subroutine calls are done with a what is called a save area. This is 18 words allocated within the subroutine. On entry the registers are saved into the previous routines save area. Then the base register is set up and the save pointer is pointed to the current save area. On exit the registers are restore, this will include the previous save area.
This means that if you call a subroutine again it will wipe out the previous calls information. To do this properly you will either need to allocate a bunch of memory to save all the registers in and advance the save pointer for each call. The other option is to allocate and free save areas at each call.
Basically you will need to implement some sort of stack to handle function calls if you want true recursive calls.
Rich
|
ok, maybe a little progress.? Knowing that standard calls do not work, as you state, means that I have to do my own.
Ok, now for some testing.....
Thank You very much.
cheers /tom c
toggle quoted message
Show quoted text
On Wed, Oct 12, 2022 at 10:11 AM Richard Cornwell < rich@...> wrote: Hi Tom,
? ?You are going to have to implement your own routines. Perhaps check
?out how Algol or PL/1 handle subroutine calls. But standard call
?routines do not support re-entrant calls.
Rich
>
> Thank you for the info.? I need to figure out how to implement your
> suggestion.? I found in the documentation on SAVE an option
>? ? ? ? ? ? SAVE? (14,12),,xxxxxxx
> where xxxx is a ds 18f area to save the regs.? I am trying to figure
> out if the change will work on DOS/VS rel 34.
>
> Cheers
> /tom c
>
>
> On Wed, Oct 12, 2022 at 9:59 AM Richard Cornwell
> <rich@...> wrote:
>
> > Hi Tom,
> >
> >? ? Typically 360/370 subroutine calls are done with a what is
> > called a save area. This is 18 words allocated within the
> > subroutine. On entry the registers are saved into the previous
> > routines save area. Then the base register is set up and the save
> > pointer is pointed to the current save area. On exit the registers
> > are restore, this will include the previous save area.
> >
> >? This means that if you call a subroutine again it will wipe out the
> >? previous calls information. To do this properly you will either
> > need to allocate a bunch of memory to save all the registers in and
> > advance the save pointer for each call. The other option is to
> > allocate and free save areas at each call.
> >
> >? Basically you will need to implement some sort of stack to handle
> >? function calls if you want true recursive calls.
> >
> > Rich
> >
> >
> >
> >
> >
> >
> >
> >
> >?
>
>
>
>
>
>
|
Not only that, but DOS/VS r 34 didnt?follow the OS calling conventions.?
Joe
toggle quoted message
Show quoted text
On Wed, Oct 12, 2022 at 10:11 AM Richard Cornwell < rich@...> wrote: Hi Tom,
? ?You are going to have to implement your own routines. Perhaps check
?out how Algol or PL/1 handle subroutine calls. But standard call
?routines do not support re-entrant calls.
Rich
>
> Thank you for the info.? I need to figure out how to implement your
> suggestion.? I found in the documentation on SAVE an option
>? ? ? ? ? ? SAVE? (14,12),,xxxxxxx
> where xxxx is a ds 18f area to save the regs.? I am trying to figure
> out if the change will work on DOS/VS rel 34.
>
> Cheers
> /tom c
>
>
> On Wed, Oct 12, 2022 at 9:59 AM Richard Cornwell
> <rich@...> wrote:
>
> > Hi Tom,
> >
> >? ? Typically 360/370 subroutine calls are done with a what is
> > called a save area. This is 18 words allocated within the
> > subroutine. On entry the registers are saved into the previous
> > routines save area. Then the base register is set up and the save
> > pointer is pointed to the current save area. On exit the registers
> > are restore, this will include the previous save area.
> >
> >? This means that if you call a subroutine again it will wipe out the
> >? previous calls information. To do this properly you will either
> > need to allocate a bunch of memory to save all the registers in and
> > advance the save pointer for each call. The other option is to
> > allocate and free save areas at each call.
> >
> >? Basically you will need to implement some sort of stack to handle
> >? function calls if you want true recursive calls.
> >
> > Rich
> >
> >
> >
> >
> >
> >
> >
> >
> >?
>
>
>
>
>
>
|
page 118 talks about reentrant modules.? also discusses reentrancy.?
The thing is, I could see nothing about memory allocation. In old DOS you ran in a partition that had a fixed size. I assume all the memory in the partition was yours while the program ran. There was no "memory management" as such, just allocate what you need in your?program.?
You probably need to write a module that starts with a "lot" of memory and manages allocation. Remember that in DOS, you don't need to be truly reentrant, just recursive. (No multi-CPU's) Each call should get a "new" save area from the routine that you write to manage memory.
Bob
toggle quoted message
Show quoted text
Not only that, but DOS/VS r 34 didnt?follow the OS calling conventions.?
Joe
On Wed, Oct 12, 2022 at 10:11 AM Richard Cornwell < rich@...> wrote: Hi Tom,
? ?You are going to have to implement your own routines. Perhaps check
?out how Algol or PL/1 handle subroutine calls. But standard call
?routines do not support re-entrant calls.
Rich
>
> Thank you for the info.? I need to figure out how to implement your
> suggestion.? I found in the documentation on SAVE an option
>? ? ? ? ? ? SAVE? (14,12),,xxxxxxx
> where xxxx is a ds 18f area to save the regs.? I am trying to figure
> out if the change will work on DOS/VS rel 34.
>
> Cheers
> /tom c
>
>
> On Wed, Oct 12, 2022 at 9:59 AM Richard Cornwell
> <rich@...> wrote:
>
> > Hi Tom,
> >
> >? ? Typically 360/370 subroutine calls are done with a what is
> > called a save area. This is 18 words allocated within the
> > subroutine. On entry the registers are saved into the previous
> > routines save area. Then the base register is set up and the save
> > pointer is pointed to the current save area. On exit the registers
> > are restore, this will include the previous save area.
> >
> >? This means that if you call a subroutine again it will wipe out the
> >? previous calls information. To do this properly you will either
> > need to allocate a bunch of memory to save all the registers in and
> > advance the save pointer for each call. The other option is to
> > allocate and free save areas at each call.
> >
> >? Basically you will need to implement some sort of stack to handle
> >? function calls if you want true recursive calls.
> >
> > Rich
> >
> >
> >
> >
> >
> >
> >
> >
> >?
>
>
>
>
>
>
|
Tom Chandler wrote: Fish, Thank you for comments. You confirmed what I thought was the issue. Looking through the fish-macros, I noticed you have a modified save macro. Should I be using that version? Eh? What "fish-macros" are you referring to? -- "Fish" (David B. Trout) Software Development Laboratories mail: fish@...
|
It was a zip file in the OLD DOS/VS files area.? That was the name of the file. along with a file that had $b transits also.
I guessed it was you, but could be wrong.
Sorry /cheers tom c.
toggle quoted message
Show quoted text
Tom Chandler wrote:
> Fish,
> Thank you for comments.? You confirmed what I thought was
> the issue. Looking through the fish-macros, I noticed you
> have a modified save macro.? Should I be using that version?
Eh? What "fish-macros" are you referring to?
--
"Fish" (David B. Trout)
Software Development Laboratories
mail: fish@...
|
Thank you to all who responded.? Each response gave me more information.
I now can nest up to 4 levels and I have getting the results that I expect.
I removed the SAVE and RETURN, replaced with storing and loading registers.? This seem to work.? The code is not pretty, but being self taught I am sure it could be improved.
|
Tom,
Peter Abel authored a book called, Programming Assembler Language (not to be confused with his book for PC Assembler) that covers what you are looking to do.? The book is primarily oriented towards DOS/VS but has a few MVS topics.
There is a chapter called "Subprograms and Overlays" that addresses what you are attempting to perform.? It discusses the usage of R13 and save areas as well as the linkage editor statements necessary.?
I have the 2nd edition that was published in 1984, the first edition was published in 1979.
Regards, Gary?
Sent from whatever device I am using.
|
Thank you for the book reference.? I am going to see if I an find it,as I am trying to learn DOS/VS asm.
/cheers /tom c
toggle quoted message
Show quoted text
Tom,
Peter Abel authored a book called, Programming Assembler Language (not to be confused with his book for PC Assembler) that covers what you are looking to do.? The book is primarily oriented towards DOS/VS but has a few MVS topics.
There is a chapter called "Subprograms and Overlays" that addresses what you are attempting to perform.? It discusses the usage of R13 and save areas as well as the linkage editor statements necessary.?
I have the 2nd edition that was published in 1984, the first edition was published in 1979.
Regards, Gary?
Sent from whatever device I am using.
|
Thank you for the book reference. I am going to see if I can find it, as I am trying to learn DOS/VS asm. -- "Fish" (David B. Trout) Software Development Laboratories mail: fish@...
|
Additional related books:
-- "Fish" (David B. Trout) Software Development Laboratories
mail: fish@...
|
Fish, Tom, Actually this one is closer to the age of DOS/VS R 34 than the 3rd edition.
https://www.thriftbooks.com/w/programming-assembler-language_peter-abel/1208200/item/28565289/?gclid=Cj0KCQjwy5maBhDdARIsAMxrkw0FFealcct8BEKSK0MapNUB0kY9w5Ba66sD7U_Q1i0hHaBoZy_-sMgaAiJQEALw_wcB#idiq=28565289&edition=2958176
Gary
Sent from whatever device I am using.
toggle quoted message
Show quoted text
-------- Original message -------- From: Fish Fish <david.b.trout@...> Date: 10/12/22 3:59 PM (GMT-05:00) Subject: Re: [H390-DOSVS] NESTED SUBROUTINES
Additional related books: http://planetmvs.com/hlasm/books.html -- "Fish" (David B. Trout) Software Development Laboratories http://www.softdevlabs.com mail: fish@...
|
Tom Chandler wrote: Fish wrote:
Tom Chandler wrote:
Fish, Thank you for comments. You confirmed what I thought was the issue. Looking through the fish-macros, I noticed you have a modified save macro. Should I be using that version? Eh? What "fish-macros" are you referring to? It was a zip file in the OLD DOS/VS files area. That was the name of the file. along with a file that had $b transits also.
I guessed it was you, but could be wrong. Ah. Yes. Those. You're right: that was me. But unfortunately I don't see any macros in either .zip file that would provide the functionality you need. But it looks like you got it working anyway. Well done! Since you said you were interested in learning Assembler, you might also be interested in joining the following Hercules-related support group too: hercules-s370asm: Forum discussing use of S/370 assembler with the Hercules emulator /g/hercules-s370asmThe folks there might not be able to help you with any specific DOS/VS questions (for questions such as those, you should continue to ask them here, in this forum), but they can certainly help you with general S/370 assembler questions/issues. Hercules has many different support forums providing support on a wide variety of topics and operating systems. For the complete list, refer to our "Technical Support" web page: * -- "Fish" (David B. Trout) Software Development Laboratories mail: fish@...
|
Gary wrote: Fish, Tom, Actually this one is closer to the age of DOS/VS R 34 than the 3rd edition.
abel/1208200/item/28565289/?gclid=Cj0KCQjwy5maBhDdARIsAMxrkw0FFealcct8BEKS K0MapNUB0kY9w5Ba66sD7U_Q1i0hHaBoZy_- sMgaAiJQEALw_wcB#idiq=28565289&edition=2958176 I'm sure it is. But isn't S/370 Assembler S/370 Assembler? Wouldn't a third edition be just as good or even BETTER than an older first or second edition? (as long as you're not a book collector of course!) -- "Fish" (David B. Trout) Software Development Laboratories mail: fish@...
|
Here's a link to the book. Note you have to "borrow" it to look in it, but this is the link to the page.
Regards, Bob
toggle quoted message
Show quoted text
Thank you for the book reference.? I am going to see if I an find it,as I am trying to learn DOS/VS asm.
/cheers /tom c
Tom,
Peter Abel authored a book called, Programming Assembler Language (not to be confused with his book for PC Assembler) that covers what you are looking to do.? The book is primarily oriented towards DOS/VS but has a few MVS topics.
There is a chapter called "Subprograms and Overlays" that addresses what you are attempting to perform.? It discusses the usage of R13 and save areas as well as the linkage editor statements necessary.?
I have the 2nd edition that was published in 1984, the first edition was published in 1979.
Regards, Gary?
Sent from whatever device I am using.
|