2

I have been trying to create a Main program that calls another program, sending it two variables. The called program then is supposed to open an output file and print the passed variables to output file, then return control to Main program.

I have created the Main program and the Sub-Program. They both compile without errors. The sub program works as stand alone program, but when I run Main program, the program branches to sub program and then fails when it tries to open the Output file.

The code is as follows. Any input on what I have done wrong would be greatly appreciated. Thank you. CALLING PROGRAM:

         MAIN     START 0
         PRINT NOGEN        SUPPRESS GENERATED INSTRUCTIONS
         STM   14,12,12(13)
         BALR  12,0
         USING *,12

     MVC   MONTH1,=C'March'     
     MVC   MONTH2,=C'June'
     LA    9,=A(MONTH1,MONTH2)  Parameters to pass stored in R9
     SR    1,1
     LOAD  EP='SEARCH.COM'
     ST    13,SAVMAIN+4

     LA    13,SAVMAIN
     LR    15,0
     BALR  14,15
     WTO   'Subprogram was successful in finding data passed'

     RETURNPT WTO   'AND IT RETURNED'

     RETURN 

     MONTH1   DS    CL12        
     MONTH2   DS    CL12
     DS   0F
     SAVMAIN  DS  18F

     END   MAIN

CALLED PROGRAM:

SEARCH START 0 REGS PRINT NOGEN SUPPRESS GENERATED INSTRUCTIONS STM R14,R12,12(R13) BALR R12,R0 USING *,R12 Set base register to R12 ST R13,SAVE+4 LA R13,SAVE WTO 'SUB PROGRAM REACHED' ******** * Or Immediate files for reading and writing. Needed only on PC/370 ******** OI OUTPUT+10,X'08' WTO 'OI PROCESSED' ******** * Open all files needed for programming assignment ******** OPEN OUTPUT WTO 'OUTPUT FILE OPENED' * ********************************************************* *** MAIN CODE *** ********************************************************* * L R8,0(R0,R9) MVC FIND1,0(R8) L R8,4(R0,R9) MVC FIND2,0(R8) WTO FIND1 WTO FIND2 MVC CTEMP,FIND1 MVC OWORD,=C'WORD 1:' PUT OUTPUT,OREC MVC CTEMP,FIND2 MVC OWORD,=C'WORD 2:' PUT OUTPUT,OREC * ********************************************************* *** EOJ PROCESSING *** ********************************************************* * ******** * Close all files needed for programming assignment ******** * ATEND EQU * CLOSE OUTPUT WTO 'Subprogram was successful in printing passed data' ********************************************************* *** END PROGRAM *** ********************************************************* * EXIT EQU * RETURN LTORG ********************************************************* **** FILE DEFINITIONS *** ********************************************************* OUTPUT DCB LRECL=29,RECFM=F,MACRF=P,DDNAME='MAINOUT.TXT' OREC DS 0CL29 OWORD DS CL12 DC CL3' ' ORESULT DS CL12 DC X'0D25' FIND1 DS CL12 FIND2 DS CL12 CTEMP DS CL12 DS 0F SAVE DS 18F END SEARCH
2
  • What symptom do you get? How does it fail?
    – Hot Licks
    Nov 28, 2011 at 1:52
  • When I run the Main program, it links to the Sub program, WTO's the 'OI PROCESSED' and then crashes. We are using the PC-370 emulator. I am pretty sure that the crash is indicating that the OPEN OUTPUT is the point of failure. I have spent about 20 hours trying to get this to work. Learned a lot in the process but still failing to get it to work.
    – subcan
    Nov 29, 2011 at 6:11

2 Answers 2

1

I realized that this question has remained unanswered. I finally figured out how to correctly perform Assembly program linkage in PC-370.

The output is commented, for the most part. I give this code in hopes of helping another student deal with this concept.

If someone comes across this and finds an error in the logic, please PM me and I will fix it.

I hope this helps those in need.

SUBCAN

This is the MAIN.MLC program that calls the SUBPRG.MLC program.

*******************************************************************
*        FILENAME  :  MAIN.MLC                                    *
*        AUTHOR    :  Subcan                                      *
*        PROFESSOR :  X                                           *
*        SYSTEM    :  ASUS P8Z68-Vpro w/I7-2600k CPU, PC/370 R4.2 *
*        SYSTEM    :  ASUS P8Z68-Vpro w/I7-2600k CPU, PC/370 R4.2 *
*        REMARKS   :  Coding two programs. A Main program and a   *
*                     Subprogram. The main program will establish *
*                     itself without using BEGIN, START, OR RETURN*
*                     Macros. The main program will define two    *
*                     Parameters to be passed to the subprogram.  *
*                     The subprogram will then print these        *
*                     parameters to an output file, then return   *
*                     control back to calling program             *
*******************************************************************
*********************************************************
***                 PROGRAM ENTRY POINT               ***
*********************************************************
*
MAIN     CSECT
         PRINT NOGEN        SUPPRESS GENERATED INSTRUCTIONS
         REGS
         STM   14,12,12(13)
         BASR  12,0
         USING *,12
         ST    13,SAVMAIN+4
         LA    13,SAVMAIN
*
*********************************************************
***                 MAIN CODE                         ***
*********************************************************
*
************
* Load passing parameters to respective variables
************
         MVC   PARAM1,=CL12'March'      
         MVC   PARAM2,=CL12'June'
************
* Load address of SUBPRG.COM into R1 then perform SVC 25
* load parameter addresses into R1 to pass to called program
************
         LA    R1,=C'SUBPRG.COM'
         SVC   25                   Load file
         LR    15,0
         LA    15,X'0210'(0,15)
         LA    R1,=A(PARAM1,PARAM2)

         LA    R2,=C'LOADED PARAMETERS TO R1$'
         SVC   209                  Write to operator

         BALR  R14,R15              Branch to SUBPRG

         LA    R2,=C'And it returned$'
         SVC   209                  Write to operator
*        
*********************************************************
***                 END PROGRAM                       ***
*********************************************************
*
         L     R13,SAVMAIN+4
         LM    R14,R12,12(R13)  
         LA    R15,0
         BR    R14
*
*********************************************************
***                 ANY LITERALS                      ***
*********************************************************
*
         LTORG
*
*********************************************************
***                 OUTPUT FIELD DEFINITIONS          ***
*********************************************************
*
PARAMS   DS   0F     
PARAM1   DS    CL12     
PARAM2   DS    CL12
*
*********************************************************
***                 RETURN ADDRESSES                  ***
*********************************************************
*
         DS   0F
SAVMAIN  DS  18F

         END   MAIN

This is the called program, SUBPRG.MLC

*******************************************************************
*        FILENAME  :  SUBPRG.MLC                                  *
*        AUTHOR    :  Subcan                                      *
*        PROFESSOR :  X                                           *
*        SYSTEM    :  ASUS P8Z68-Vpro w/I7-2600k CPU, PC/370 R4.2 *
*        REMARKS   :  Coding two programs. A Main program and a   *
*                     Subprogram. The main program will establish *
*                     itself without using BEGIN, START, OR RETURN*
*                     Macros. The main program will define two    *
*                     Parameters to be passed to the subprogram.  *
*                     The subprogram will then print these        *
*                     parameters to an output file, then return   *
*                     control back to calling program             *
*******************************************************************
*********************************************************
***                 PROGRAM ENTRY POINT               ***
*********************************************************
*
SUBPRG   CSECT
         REGS
         PRINT NOGEN        SUPPRESS GENERATED INSTRUCTIONS
         STM   14,12,12(13)
         BASR  12,0
         USING *,12
         ST    13,SAVE+4
         LA    13,SAVE
*
*********************************************************
***                 MAIN CODE                         ***
*********************************************************
* 
         LA    R2,=C'Sub program reached$'
         SVC   209                  Write to operator
************
* Use the Assist Macros to perform open and writing of files
* Look to PC-370 DOCS\USER.DOC for more info
* XFILO - This extended instruction redirects the output from XPRNT.
* XPRNT - Print record. Ends with ,length to set length of record.
*           Character string always ends with $ to show end of line.
************
         XFILO =C'SUBOUT.TXT'

         LA    R2,=C'Output file opened$'
         SVC   209                  Write to operator

         L     R8,0(R1)
         MVC   PARAM1(12),0(R8)
         L     R8,4(R1)
         MVC   PARAM2(12),0(R8)

         XPRNT =CL51' The following are words passed by Calling Program.',51
         XPRNT =C'  ',2                 SKIP ONE LINE
         MVC   ORESULT,PARAM1
         MVC   OWORD,=CL12' WORD 1:'
         XPRNT OREC,27

         MVC   ORESULT,PARAM2
         MVC   OWORD,=CL12' WORD 2:'
         XPRNT OREC,27

         MVI   PARAM1+11,C'$'       MVI $ to provide end of line
         LA    R2,PARAM1
         SVC   209                  Write to operator

         MVI   PARAM2+11,C'$'       MVI $ to provide end of line    
         LA    R2,PARAM2
         SVC   209                  Write to operator

         LA    R2,=C'Subprogram was successful in printing passed data$'
         SVC   209                  Write to operator
*        
*********************************************************
***                 END PROGRAM                       ***
*********************************************************
*
EXIT     EQU   *
         L     R13,SAVE+4
         LM    R14,R12,12(R13)  
         LA    R15,0
         BR    R14
*
*********************************************************
***                 ANY LITERALS                      ***
*********************************************************
*
         LTORG
*
*********************************************************
***                 OUTPUT FIELD DEFINITIONS          ***
*********************************************************
*
OREC     DS   0F
OWORD    DS    CL12
         DC    CL3' '
ORESULT  DS    CL12
*
*********************************************************
***                 CHARACTER FIELD DEFINITIONS       ***
*********************************************************
*
PARAM1   DS    CL12     
PARAM2   DS    CL12
*
*********************************************************
***                 RETURN ADDRESSES                  ***
*********************************************************
*
         DS   0F
SAVE     DS  18F
         END   SUBPRG
0

Tough one -- probably not many BAL programmers left around here.

I'm assuming you did the subroutine entry protocol correctly (I only sorta knew it once), but you might want to check that and also see if there are any added requirements on subroutine call/entry (register saving and the like) for using the WTO and OPEN macros.

A little suspicious of the OI OUTPUT+10,X'08' -- it seems odd to be ORing a bit on in the middle of a DCB like that, vs using some macro or at least referring to a label.

1
  • You need to OI the OUTPUT file in order to change it from EBCDIC to ASCII. This is only required for the PC-370 emulator. I have tried everything that I can think of to ensure that I have accounted for all the registry issues. Thanks for your input. If I get it I will be sure to post the results.
    – subcan
    Nov 29, 2011 at 6:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.