Page 1 of 2

Help in understanding an Assembler Program

PostPosted: Thu Sep 01, 2016 2:10 am
by ramkumar1992sp
Hello Experts,

Can someone please help me in understanding the below Assembler program ? I have been referring online manuals and also reading MVS Assembler Language by Kevin McQuillen and Anne Prince but still haven't been able to understand the below program.

I added the notes after each statement.Can someone please correct me on those notes?


         PUNCH '      ALIAS XXXXXLST '                  
XXXXXARG START 0                                        
         ENTRY XXXXXLST ->It looks like XXXXXLST is the starting point of this subprogram.
                           
         EXTRN XXXXXQLK->It looks like we are defining XXXXXQLK as an external module.                                
         USING *,15                                      
         B     COIBMEND                                  
*                                                        
         DC    C'XXXXX COPYRIGHT IBM CORP. 19XX'      
         DC    C'XXXXXARG1,0'                            
*                                                        
R1       EQU   1 -> defining R1 as Register 1                                        
R2       EQU   2 -> defining R2 as Register 2                                        
R3       EQU   3  ->defining R3 as Register 3                                        
RF       EQU   15 -> defining RF as Register 15
COIBMEND EQU   *                                        
         BALR  RF,0 -->This and the below USING command will insert the address of the next sequential instruction into RF and will set it as the base register.
         USING *,RF                                                    
         SAVE  (14,12)-> Save the contents of Registers 14 through 12.                                                  
         LA    R2,XXXXXLST -->Load the address of XXXXXLST to R2 Register.                                            
         LH    R3,=H'4'--> Loads the half word 4 to Register R3.                                                
RESUME   MVC   0(4,R2),0(R1)-> Moves the contents of Register R1 to Register R2 after 4 Bytes.                                          
         TM    0(R1),X'80' -->Test under Mask Condition.X’80’ will be converted to1000 0000and the left most bit will be the selected bit.
I know what this is.but I’m not sure why we are doing this.
         BO    EXIT--> Exit the program if selected bit was 1.                                                    
         AR    R1,R3--> Add register 3 contents to Register 1                                                    
         AR    R2,R3 -->Add register 3 contents to Register 2                                                    
         B     RESUME-> GOTO RESUME                                                  
EXIT     RETURN (14,12),RC=0 (control is returned to calling programming)               1-5
XXXXXLST DS    0D --> I read that this is to align the location counter to a doubleword.but not sure why we are doing or how.                                                    
ARG01    DC    F'0'-->counter for ARG01(initially -0)                                                    
ARG02    DC    F'0'-->counter for ARG01(initially -0)                                                    
ARG03    DC    F'0'-->counter for ARG01(initially -0)                                                    
ARG04    DC    F'0'-->counter for ARG01(initially -0)                                                    
ARG05    DC    F'0'-->counter for ARG01(initially -0)                                                    
ARG06    DC    F'0'-->counter for ARG01(initially -0)      
ARG07    DC    F'0'-->counter for ARG01(initially -0)                                                    
ARG08    DC    F'0'-->counter for ARG01(initially -0)                                                    
ARG09    DC    F'0'-->counter for ARG01(initially -0)                                                    
ARG10    DC    F'0'-->counter for ARG01(initially -0)                                                    
PATCHES  DC    4F'0'               XXARG PATCH AREA                    
PATCHCON DC    A(XXXXXQLK)         ADDR OF CSECT CONTAINING PATCH AREA --> Address constant for XXXXXQLK  
         LTORG                                                          
         END                                                            
                                             
                                 
 


Thanks,
Ram Kumar

Re: Help in understanding an Assembler Program

PostPosted: Thu Sep 01, 2016 2:29 am
by Robert Sample
Basically the parameter list is being copied to XXXXXLST. The standard convention (as long as 64-bit addressing is not involved) in Assembler is that parameters are passed by address, and the last parameter has the first bit set to denote the end of the list (since 24-bit and 31-bit addresses will NOT use the first bit of the word).
RESUME   MVC   0(4,R2),0(R1)-> Moves the contents of Register R1 to Register R2 after 4 Bytes.
Actually, this moves 4 bytes of memory, starting with the address that R1 points to, to the memory location pointed to by R2. The contents of R1 and R2 do not change -- merely the memory locations pointed to by R1 and R2 are changed. The Tm instruction is being used to detect the end of the parameter list and stop the copy process.

Re: Help in understanding an Assembler Program

PostPosted: Thu Sep 01, 2016 3:36 am
by ramkumar1992sp
Thanks Robert.I will get back to you after reviewing the program and the instruction set again in the context of what you said.

In the meanwhile,I'm not sure what exactly XXXXXLST is. Is it a subprogram ? I didn't find a source for it when I looked at the libraries.

I found an entry in the load library where it said it was an ALIAS of XXXXXARG. What does that mean? XXXXXARG is the program that I showed in my first post.


Command ===>                                                  Scroll ===> CSR  
           Name             Prompt  Alias-of       Size     TTR     AC   AM   RM  
_________ XXXXXLST                XXXXXARG        00000118   00AE11   00    24   24


 


Thanks,
Ram Kumar

Re: Help in understanding an Assembler Program

PostPosted: Thu Sep 01, 2016 7:20 am
by steve-myers
ENTRY XXXXXLST

The ENTRY Assembler instruction directs the Assembler to define XXXXXLST as an external symbol available to other modules statically linked with this module. It is not the address of the first instruction to execute.

         PUNCH '      ALIAS XXXXXLST '                  

The PUNCH Assembler directs the Assembler to write

 ALIAS XXXXXLST

before the first object "deck" output record. I think whoever wrote this violated IBM's rules for structuring modules; the ALIAS Binder statement should be in Binder control statements, independent of object input. There are several other rule violations, which I won't go into here.

I prepared this JCL -
//A       EXEC PGM=ASMA90,PARM='OBJECT,NODECK,XREF(SHORT)'
//SYSPRINT DD  SYSOUT=*
//SYSLIB   DD  DISP=(SHR,PASS),DSN=SYS1.MACLIB
//SYSLIN   DD  DISP=(MOD,PASS),UNIT=SYSDA,SPACE=(TRK,(1,1,1)),
//             DSN=&&OBJSET(XXXXXARG)
//LOAD     DD  DISP=(MOD,DELETE),UNIT=SYSALLDA,SPACE=(TRK,0),
//             DSN=&SYSUID..XXLST.LOAD
//SYSIN    DD  *

Your corrected program

//B       EXEC PGM=IEWL,PARM='MAP,LIST,XREF,LET'
//SYSPRINT DD  SYSOUT=*
//XXLIB    DD  DISP=(OLD,PASS),DSN=&&OBJSET
//SYSLMOD  DD  DISP=(,CATLG),UNIT=SYSDA,SPACE=(TRK,(1,1,1)),
//             DSN=&SYSUID..XXLST.LOAD
//SYSLIN   DD  *
       INCLUDE XXLIB(XXXXXARG)
*        ALIAS XXXXXLST  *** THIS IS WHERE THE ALIAS STATEMENT BELONGS
          NAME XXXXXARG(R)

I get this in the ISPF directory list -
Command ===>                                                  Scroll ===> PAGE
    Name     Prompt         Alias-of      Size       TTR      AC    AM     RM
 . XXXXXARG                             000000A8    000003    00     24     24
 . XXXXXLST                 XXXXXARG    000000A8    000003    00     24     24

A PDS directory "alias" is just an alternate name for the member. For load modules, the Binder stores the name of the primary member in the alias directory entry. In this list ISPF is just echoing the data in the directory entry; it may not be correct.

Mr. Sample's analysis of what the module does is correct. Technically, there is a buffer overflow type error here, along with other errors that you can figure out your self.

Re: Help in understanding an Assembler Program

PostPosted: Thu Sep 01, 2016 7:21 am
by Robert Sample
An alias is an alternate label for a load module (aliases can also occur in catalogs). This means you can put // EXEC PGM=XXXXXLST or // EXEC PGM=XXXXXARG and the same program will be loaded and executed. An alias is NOT a subprogram, and you won't generally find source for it -- a load module alias is created with the binder / linkage editor, not the assembler or compiler.

Re: Help in understanding an Assembler Program

PostPosted: Thu Sep 01, 2016 1:40 pm
by steve-myers
This is my version with the buffer overflow and other issues corrected.
XXXXXARG START 0
         ENTRY XXXXXLST
         EXTRN XXXXXQLK
         USING *,15
         B     COIBMEND            Br around copyright notice
*
         DC    C'XXXXX COPYRIGHT IBM CORP. 19XX'
         DC    C'XXXXXARG1,0'
*
R1       EQU   1
R2       EQU   2
R3       EQU   3
R4       EQU   4
RE       EQU   14
RF       EQU   15
         DC    0H'0'
COIBMEND EQU   *
         SAVE  (14,12)             Save registers
*        BALR  RF,0                Not
*        USING *,RF                 necessary
         XC    ARGCLEAR,ARGCLEAR   Clear the area
         LA    R2,XXXXXLST         Compute address of start of output
         LH    R3,=H'4'            Set reg 3 = bytes in a word
         LR    RE,R1               Copy start of sarguments to RE
         SR    R4,R4               Set number of arguments = 0
COUNT    LA    R4,1(,R4)           Add 1 to number of arguments
         TM    0(RE),X'80'         End of arguments?
         BO    TESTC               Br if end of arguments
         AR    RE,R3               Compute address of next argument
         B     COUNT               Try again
TESTC    CH    R4,=AL2(ARGS)       Test if too many arguments
         BNH   RESUME              Br if arguments will fit in table
         RETURN (14,12),RC=16      Oops, buffer overflow
RESUME   MVC   0(4,R2),0(R1)       Copy one argument
         TM    0(R1),X'80'         End?
         BO    EXIT                Yes
         AR    R1,R3               Compute address of next argument
         AR    R2,R3
         B     RESUME              Do it again
EXIT     RETURN (14,12),RC=0       Restore registers & return
XXXXXLST DC    0D'0'
ARG01    DC    F'0'
ARG02    DC    F'0'
ARG03    DC    F'0'
ARG04    DC    F'0'
ARG05    DC    F'0'
ARG06    DC    F'0'
ARG07    DC    F'0'
ARG08    DC    F'0'
ARG09    DC    F'0'
ARG10    DC    F'0'
ARGCLEAR EQU   ARG01,*-ARG01
ARGS     EQU   (*-ARG01)/L'ARG01
PATCHES  DC    4F'0'
PATCHCON DC    A(XXXXXQLK)
         LTORG
         END

Re: Help in understanding an Assembler Program

PostPosted: Thu Sep 01, 2016 6:35 pm
by ramkumar1992sp
Thank you so much Steve and Robert.I will get back with follow up questions after reviewing this program again with all the new details.


Thanks,
Ram Kumar

Re: Help in understanding an Assembler Program

PostPosted: Fri Sep 02, 2016 9:23 pm
by ramkumar1992sp
This assembler program is called by a COBOL program and below is the how its called.There are 9 parameters passed .

XXXXX71W- OS VS COBOL program calling ‘XXXXXARG’ ASM


001588 955136 2025-SAVE-TABLE-INDEX.                                      
001589 956032     SET LAST-MSTAB-ENTRY TO MS-X1.                          
001590 956928     CALL 'XXXXXARG' USING XXXXX-DAYS XXXXX-TABLE        
001591 957824         LOOP-CONTROL-DATA XXXXX-RECORD BIN-1 BIN-1 BIN-1    
001592 958720         BIN-1 BIN-1.                                        
001593 958800     SET X2F WKF-X1F REQ-XF TO FIRST-XXXXX.              
001594 958820     SET X2L REQ-XL TO LAST-XXXXX.                        
001595 959616     GO TO 0100-START-SCHEDULING-PASS.                      
 


Now I’m trying to understand the purpose of copying the parameter list to ‘XXXXXLST’ in ‘XXXXXARG’.

I was searching through the library to see where ‘XXXXXLST’ is used and I found an another ASM program ‘XXXXX1S1' in the same COBOL program that called ‘XXXXXARG’.This call is much after the above call to ‘XXXXXARG’.So far it looks like none of the above parms are modified in between the call to ‘XXXXXARG’ and call to ‘XXXXX1S1'


XXXXX71W- OS VS COBOL program calling 'XXXXX1S1 ASM


     MOVE 'N' TO CONFLICT-SWCH.                            
     CALL 'XXXXX1S1'.                                      
     IF CONFLICT-SWCH = 'Y'                                
         GO TO 0830-ANY-CLASSES-LEFT.                      
 


Code from ‘XXXXX1S1' Program



COIBMEND EQU   *                                                        
          SAVE  (14,12)                                                  
          L     RA,=A(XXXXXLST)              LOAD ADDR OF PARAMETER LIST
          LM    R1,R4,0(RA)                                              
          LA    RF,XXXXX1S2                                              
          USING XXXXX,RF                                              
          LA    RC,TESTBITS                  POINT BR REG TO TM INST    
          LA    RE,ASGNBITS                                              
          B     STARTOP                                                  
 XXXXX1S2 SAVE  (14,12)                                                  
          L     RA,=A(XXXXXLST)              LOAD ADDR OF PARAMETER LIST
          LM    R1,R4,0(RA)                                              
          LA    RC,XORBITS                   POINT BR REQ TO XOR INST    
          LA    RE,RETURNIT                                              

 


Can someone please help me with the below queries ?
1) My requirement is to convert the assembler program to COBOL.As far as ‘‘XXXXXARG’ is concerned,since its only copying the parameter list.I m thinking of removing 'XXXXXARG' and then call 'XXXXX1S1 by “using phrase” as shown below.

     MOVE 'N' TO CONFLICT-SWCH.                            
     CALL ‘XXXXX1S1’ USING XXXXX-DAYS XXXXX-TABLE  
                                 LOOP-CONTROL-DATA XXXXX-RECORD BIN-1 BIN-1 BIN-1  
                                 BIN-1 BIN-1.                                        
     IF CONFLICT-SWCH = 'Y'                                
         GO TO 0830-ANY-CLASSES-LEFT.  
 

Does this idea look correct?

2) There are about six COBOL programs that call the above ASM program ‘XXXXXARG’.5 of them pass 9 parameters and one of them 8. The Assembler program had 10 ARG defined.How does this work ?


Thanks,
Ram Kumar

Re: Help in understanding an Assembler Program

PostPosted: Fri Sep 02, 2016 9:43 pm
by Robert Sample
The called program uses that first bit of the address to stop processing passed arguments. As long as the code doesn't try to reference the extra arguments, a called program can have more arguments than the calling program passes as parameters. The reverse is also true -- the calling program can pass more parameters than the called program uses as arguments. Neither mismatch is a good programming technique since you can easily have memory issues, but the system doesn't check for such issues.

Re: Help in understanding an Assembler Program

PostPosted: Fri Sep 02, 2016 11:27 pm
by ramkumar1992sp
Thanks Robert for the clarification regarding the mismatch of the parameters between the calling ASM program and the called COBOL program.

As far my first query goes,does it sound ok to remove the program that's just copying the parameters and instead directly pass the parameters while calling the second program 'XXXXX1S1' ? XXXXX1S1 would also be converted to a Cobol program.

Thanks,
Ram Kumar