PC / 370 IBM Mainframe Assembly - 程序链接无法正常工作

时间:2011-11-28 00:27:40

标签: assembly

我一直在尝试创建一个调用另一个程序的Main程序,向它发送两个变量。然后被调用程序打开输出文件并将传递的变量打印到输出文件,然后将控制权返回给主程序。

我创建了主程序和子程序。他们都编译没有错误。子程序作为独立程序工作,但是当我运行主程序时,程序分支到子程序,然后在尝试打开输出文件时失败。

代码如下。对我所做错的任何意见都将不胜感激。谢谢。 呼叫计划:

         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 个答案:

答案 0 :(得分:1)

我意识到这个问题一直没有答案。我终于想出了如何在PC-370中正确执行汇编程序链接。

在大多数情况下,输出被评论。我给出了这段代码,希望能帮助其他学生处理这个概念。

如果有人碰到这个并发现逻辑错误,请PM我,我会解决它。

我希望这可以帮助那些有需要的人。

SUBCAN

这是调用SUBPRG.MLC程序的MAIN.MLC程序。

*******************************************************************
*        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

这是被调用的程序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

答案 1 :(得分:0)

艰难的一个 - 可能没有多少BAL程序员留在这里。

我假设你正确地完成了子程序入口协议(我只知道它曾经知道过一次),但你可能想检查一下,并查看子程序调用/输入是否有任何附加要求(寄存器保存等等) )使用WTO和OPEN宏。

OI OUTPUT+10,X'08'有点怀疑 - 在这样的DCB中间进行OR运算似乎很奇怪,与使用某些宏或至少引用标签相比。