Structured Assembler Macros: The While Loop

Build a while loop using the structured assembler Do macro. Here is the relevant code:

         DO WHILE=(CP,X,LT,=P'10')                                      
            AP   X,=P'1'                                                
            MVC  XOUT,EDWD                                              
            ED   XOUT,X                                                 
            PUT  FILEOUT1,RECOUT                                        
         ENDDO                                                                                                                  

The test at the top of the loop compares X with a packed decimal 10 and enters the loop if X is less than 10. Sweet! Here’s the complete program that makes it work:

//CSUP004A JOB (ASSY),'WOOLBRIGHT',CLASS=A,MSGCLASS=A,                  
//   NOTIFY=&SYSUID,MSGLEVEL=(1,1)                                      
//ASM      EXEC PROC=HLASMCLG                                           
//C.SYSLIB   DD   DSN=SYS1.MACLIB,DISP=SHR                              
//           DD   DSN=HLA.SASMMAC2,DISP=SHR                             
//SYSIN    DD   *                                                       
         COPY   ASMMSP                                                  
         TITLE  'SKELETON ASSEMBLER PROGRAM'                            
         PRINT  ON,DATA,NOGEN                                           
******************************************************************      
*                                                                *      
*   PROGRAMMER:  WOOLBRIGHT                                      *      
*   COMMENTS  :  ASM SKELETON PROGRAM                            *      
*                                                                *      
******************************************************************      
*                                                                *      
*     REGISTER EQUATES                                           *      
*                                                                *      
******************************************************************      
R0       EQU   0                                                        
R1       EQU   1                                                        
R2       EQU   2                                                        
R3       EQU   3                                                        
R4       EQU   4                                                        
R5       EQU   5                                                        
R6       EQU   6                                                        
R7       EQU   7                                                        
R8       EQU   8                                                        
R9       EQU   9                                                        
R10      EQU   10                                                       
R11      EQU   11                                                       
R12      EQU   12                                                       
R13      EQU   13                                                       
R14      EQU   14                                                       
R15      EQU   15                                                       
******************************************************************      
*                                                                *      
*     SYMBOLIC EQUATES                                           *  
 *                                                                *      
******************************************************************      
MACRO3   CSECT                         STANDARD ENTRY CODE              
         STM   R14,R12,12(R13)                                          
         BASR  R12,R0                  ESTABLISH...                     
         USING *,R12                   ADDRESSABILITY                   
         ST    R13,SAVEAREA+4          BACKWARD CHAIN CALLER            
         LA    R13,SAVEAREA            ADDRESS OF MY SAVE AREA          
******************************************************************      
* BEGIN THE PROGRAM LOGIC. FIRST OPEN THE OUTPUT FILE         
******************************************************************      
         OPEN  (FILEOUT1,(OUTPUT))                                      
         ZAP   X,=P'0'                                                                                                         
LOOP     EQU   *                                                        
         DO WHILE=(CP,X,LT,=P'10')                                      
            AP   X,=P'1'                                                
            MVC  XOUT,EDWD                                              
            ED   XOUT,X                                                 
            PUT  FILEOUT1,RECOUT                                        
         ENDDO                                                                                                                  
EXIT     EQU   *                                                        
         CLOSE (FILEOUT1)                                               
         L     R13,SAVEAREA+4          POINT AT OLD SAVE AREA           
         LM    R14,R12,12(R13)         RESTORE THE REGISTERS            
         LA    R15,0                   RETURN CODE = 0                  
         BR    R14                     RETURN TO OPERATING SYSTEM       

******************************************************************      
              *                                                                *      
*     OUTPUT FILE - DATA CONTROL BLOCK                           *      
*                                                                *      
******************************************************************      
               DC X'FFFFFFFF'                                           
FILEOUT1 DCB   DSORG=PS,                                               X
               MACRF=(PM),                                             X
               DEVD=DA,                                                X
               DDNAME=FILEOUT1,                                        X
               RECFM=FB,                                               X
               LRECL=80                                                 

******************************************************************      
*                                                                       
*    OUTPUT RECORD AREA                                                 
*                                                                       
******************************************************************      
RECOUT   DS   0CL80               PRINT AREA                            
         DC    CL10' '                                                  
XOUT     DS    CL5                                                      
         DC    CL65' '                                                  
EDWD     DC    X'4020212060'                                            
X        DS    PL2                                                      
******************************************************************      
*                                                                       
*    REGISTER SAVE AREA                                                 
*                                                                       
******************************************************************      
SAVEAREA DS  18F                                                        
******************************************************************      
*                                                                       
*    LITERAL POOL                                                       
*                                                                       
******************************************************************      
         LTORG *                                                        
         END   MACRO3                                                   
/*                                                                      
//G.SYSABOUT DD SYSOUT=*                                                
//G.SYSUDUMP DD SYSOUT=*                                                
//G.FILEOUT1 DD SYSOUT=*                                                                                                          
//                                                                      

Leave a comment

Filed under IBM Mainframe Assembler

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s