Page 2 of 5

Re: Trouble with assembler subroutines

PostPosted: Tue Nov 22, 2011 5:09 pm
by RISCCISCInstSet
Anyway, do you have any further hints as to how I have my program invoke a subroutine without crashing?

Re: Trouble with assembler subroutines

PostPosted: Tue Nov 22, 2011 5:50 pm
by steve-myers
Sorry, no. This is something you'll have to learn yourself!

Re: Trouble with assembler subroutines

PostPosted: Tue Nov 22, 2011 5:58 pm
by Robert Sample
What I need to understand is: how shall I start up a simple internal subroutine such that I can call it? To call the subroutine, I invoke BAL
R14,subroutine - with subroutine being a selected name. To return from a subroutine, I code BR R14.
This says you understand the basics. If you have trouble after using BAL and BR, then the issue is not with invocation of the subroutine but somewhere else.

And asking how to get something to run "without crashing" is totally useless -- either you are running the code and getting a specific abend code (in which case you should post the code at a minimum), or you are not running the code and just guessing about crashing.

Re: Trouble with assembler subroutines

PostPosted: Tue Nov 22, 2011 6:00 pm
by enrico-sorichetti
did You care to look at the link I provided You with ? looks like not!
quite a bit of info there and additional links.
anyway the quirks of CALLing <subroutines> are clearly explained here
http://publibz.boulder.ibm.com/cgi-bin/ ... 0522045539

Re: Trouble with assembler subroutines

PostPosted: Wed Nov 23, 2011 2:13 am
by dick scherrer
Hello,

do you have any further hints as to how I have my program invoke a subroutine without crashing?
Possibly - if you will invest a bit of time to show us what is wrong.

Posting "it didn't work" is probably the worst that can be posted when looking for help. We knew it didn't. So, post some specifics.

My guess is that you have done something incorrectly with register usage or have "walked on" some of memory (instructions).

Re: Trouble with assembler subroutines

PostPosted: Wed Nov 23, 2011 6:02 am
by RISCCISCInstSet
There's something interesting. How do you walk on memory?

Re: Trouble with assembler subroutines

PostPosted: Wed Nov 23, 2011 6:03 am
by RISCCISCInstSet
My stupid gibberish:
LAB6A    SUBENTRY
LAB6A    CSECT
       
         BALR    12,0
         USING   *,12
         SAVE    (14,12)
         BALR    12,0
         USING   *,12 
         LA      2,SAVEAREA 
         ST      2,8(,13)
         ST      13,4(,2)
         LR      13,2
         LA      1,DATA
         
         LM 14,12,12(13)
         OI 15(13),X'01'
         LA      15,0(0,0)
         
         
         
         BAL    15,SUMRTN
         BAL    15,SUMRTN
         BAL    15,SUMRTN
         LA     3,X'00000000'
         LA     4,X'00000001'
         LA     5,X'00000063'
         ZAP   B,=P'0'
         ZAP   SUM,=P'0'
         ZAP   A,=P'1'

LOOP     DS    0H
         AP    B,A
         AP    SUM,B
 
         BXLE  3,4,LOOP
         
         MVC  FIELD,MASK
         ED   FIELD,SUM
         WTO  MF=(E,WTOMSG)
         SUBEXIT

WTOMSG   DC AL2(WTOMEND-*,0)
HELLO    DC  C'THE SUM OF THE NUMBERS FROM 1 TO 100 IS '
FIELD    DS CL10
WTOMEND  EQU *

*
MASK     DC X'40206B2020206B202020'
PRNTLINE DS CL133
SUM      DS PL4
B        DS PL4
A        DS PL4
C        DS PL4
CB       DS PL4
DB       DS PL4
SAVEAREA DS 18F
DATA     DC CL5'00800'
SUMRTN   DS      0H
         WTO 'NONSENSE'
         BR      15

ENDPGM   DS  D

    END  LAB6A

Re: Trouble with assembler subroutines

PostPosted: Wed Nov 23, 2011 7:10 am
by Robert Sample
I can certainly see why your program is crashing. Everything up to the LA 1,DATA is okay -- bizarre from the repeated code, but not causing a crash. The LM 14,12,12(13) destroys everything else you'd done up to that point -- it restores register 1 to the value it had when the operating system turned control over to your program, wipes out register 12 (which is being used as your base register). This makes the rest of your program hazardous since the base displacements are no longer valid since they're using register 12 that just got restored to the original value, not the value the BALR 12,0 put in it.

And since you are so careful to use WTO M=(E,WTOMSG) the first time with a length and all that, why use WTO 'NONSENSE' in the subroutine?

Re: Trouble with assembler subroutines

PostPosted: Wed Nov 23, 2011 7:18 am
by steve-myers
RISCCISCInstSet wrote:There's something interesting. How do you walk on memory?
"Walking on memory" is a phrase to indicate something is altering your program, almost always that "something" is your program.

Re: Trouble with assembler subroutines

PostPosted: Wed Nov 23, 2011 9:07 am
by steve-myers
There are a lot of problems in your code; many more than Mr. Sample indicated. You'll learn more if you figure them out yourself.