Using STORAGE macro with QSAM



High Level Assembler(HLASM) for MVS & VM & VSE

Using STORAGE macro with QSAM

Postby pintu1228 » Wed Mar 23, 2016 3:48 am

Hi everyone, was wondering if you can help me out. I wanted to know if there is an easier way to do the following. My code works but I feel like there is a lot things going out with multiple loops and wanted to see if anyone can help me condense the code i have attached.

In my code I have created 3 subroutines (insert, delete, and print).

Goals:

Each line in the file is 40 bytes long and contains: one letter X in column 1, a positive integer K which is 5 digits long in columns 3-7, and spaces in columns 6-40.

1. Using the STORAGE macro request space for a table of 20 packed-decimal integers, each 3 bytes long. Initialize all of the table to the value -1.
2. Store the address of the table in a fullword variable(used TABLEADD in my code), store the size of the table in a fullword variabl(used TABSIZE in my code).
3. Declare a fullword variable named something like INUSE to store the current number of values in the table.
4. If X = 'I', insert the number K into the table at the end and update INUSE. If X = 'P', print the contents of the entire table (including the -1s at the end, if any) with 5 numbers per line. (Ignore the value of K on this line.) If X = 'D', delete one number from the beginning of the table, move the remaining numbers up to the beginning and update INUSE. (Bear in mind that the unused part of the table should all be -1s.)



//KC03LA JOB ,'R',MSGCLASS=H,REGION=2048K                  
//STEP1 EXEC PROC=ASMACLG                                                            
//C.SYSLIB DD DSN=SYS1.MACLIB,DISP=SHR                                  
//         DD DSN=KC02293.SYS2.MACLIB,DISP=SHR                          
//C.SYSIN DD *                                                          
MAIN     CSECT                                                          
         PRINT NOGEN                  
         STM   14,12,12(13)            
         LR    12,15                  
         USING MAIN,12                
         LA    14,MAINSAVE            
         ST    13,4(0,14)              
         ST    14,8(0,13)              
         LR    13,14                  
*                                      
         OPEN  (INDCB,(INPUT))        
         LTR   15,15                  
         BZ    OPEN10K                
         ABEND 222,DUMP                
*                                      
OPEN10K  OPEN  (OUTDCB,(OUTPUT))      
         LTR   15,15                  
         BZ    OPEN20K                
         ABEND 333,DUMP                
*                                      
OPEN20K  DS    0H                      
         LA    1,OBTMEM                
         BAL   11,ALCTE                
*                                      
LOOP1    GET   INDCB,BUFFER            
         CLI   EOFFLAG,C'Y'            
*                                      
         BZ    ENDLOOP                
         CLI   BUFFER,C'P'                                              
         BZ    PRINTCLL                                                
         CLI   BUFFER,C'I'                                              
         BZ    INSRTCLL                                                
         CLI   BUFFER,C'D'                                              
         BZ    DELTECLL                                                
         B     LOOP1                                                    
*                                                                      
PRINTCLL DS    0H                                                      
         LA    1,PRNTPLST                                              
         BAL   11,PRNT                                                  
         B     LOOP1                                                    
*                                                                      
INSRTCLL DS    0H                                                      
         PACK  NBR(3),BUFFER+2(5)                                      
         PUT   OUTDCB,=CL80'CALLING INSERT'                            
*                                                                      
         LA    1,INSTPLST                                              
         BAL   11,INSRT                                                
         B     LOOP1                                                    
*                                                                      
DELTECLL DS    0H                                                      
         PUT   OUTDCB,=CL80'CALLING DELETE'                            
         LA    1,INSTPLST                                              
         BAL   11,DELTE                                                
         B     LOOP1                                                    
*                                                                      
ENDLOOP  DS    0H                                                      
*                                                                      
         L     9,TABSIZE                                                
         SR    4,4                                                      
         M     4,=F'3'                                                  
         STORAGE RELEASE,LENGTH=(5),ADDR=TABLEADD                      
*                                                                      
         CLOSE (INDCB)              
         LTR   15,15                
         BZ    CLOSE10K              
         ABEND 555,DUMP              
*                                    
CLOSE10K CLOSE (OUTDCB)              
         LTR   15,15                
         BZ    CLOSE20K              
         ABEND 666,DUMP              
*                                                                      
CLOSE20K DS    0H                                                      
*                                                                      
         L     13,4(0,13)                                              
         LM    14,12,12(13)                                            
         BR    14                                                      
         LTORG                                                          
***************************************************************        
MAINSAVE DS    18F'-1'                
NBR      DS    PL3                    
TABLEADD DC    F'0'                    
TABSIZE  DC    F'0'                    
TMPSIZE  DC    F'0'                    
INUSE    DC    F'0'                    
BUFFER   DC    40C' '                  
EMPTY    DC    80C' '                  
*                                                                      
OBTMEM   DC    A(TABLEADD)                                              
         DC    A(TMPSIZE)                                              
         DC    A(TABSIZE)                                              
         DC    A(INUSE)                                                
*                                                                      
PRNTPLST DC    A(TABLEADD)                                              
         DC    A(TMPSIZE)                                              
*                                                                      
INSTPLST DC    A(TABLEADD)                                              
         DC    A(TMPSIZE)                                              
         DC    A(INUSE)                                                
         DC    A(NBR)                                                  
*                                                                      
***************************************************************        
INDCB    DCB   DDNAME=INPUT,                                           X
               DEVD=DA,                                                X
               DSORG=PS,                                               X
               MACRF=GM,                                               X
               RECFM=FB,                                               X
               LRECL=40,                                               X
               EODAD=EOF1                                              
*                                                                      
EOFFLAG  DC    C'N'                                                    
*                                                                      
EOF1     MVI   EOFFLAG,C'Y'                                            
         BR    14                                                      
*                                                                      
OUTDCB   DCB   DDNAME=OUTPUT,                                          X
               DEVD=DA,                                                X
               DSORG=PS,                                               X
               MACRF=PM,                                               X
               RECFM=FBA,                                              X
               LRECL=80                                                
*                                                                      
***********INSERT SUBROUTINE***********************************        
INSRT    DS    0H                                                      
         STM   2,8,ISAVE                                                
         ST    11,RSAVE                                                
         LM    2,5,0(1)                                                
         L     6,0(0,3)                                                
         L     7,0(0,4)                                                
         CR    6,7                                                      
         BE    RESIZE                                                  
DONE     DS    0H                                                      
         L     6,0(0,2)                                                
         L     7,0(0,4)                                                
         LTR   7,7                                                      
         BZ    ADD                                                      
         LR    8,7                                                      
RPT      LA    6,3(0,6)                                                
         BCT   8,RPT                                                    
ADD      DS    0H                                                      
         ZAP   0(3,6),0(3,5)                                            
         LA    7,1(0,7)                                                
         ST    7,0(0,4)                                                
         LM    2,8,ISAVE                                                
         L     11,RSAVE                                                
         BR    11                                                      
*                                                                      
RESIZE   DS    0H                                                      
         SLA   6,1(0)                                                  
         ST    6,TMPSIZE                                                
         LA    1,OBTMEM                                                
         BAL   11,ALCTE                                                
         PUT   OUTDCB,=80C' '
         PUT   OUTDCB,=CL80'WE HAVE ALLOCATED MORE MEMORY FOR THE TABLE'                
         PUT   OUTDCB,=80C' '                                          
         PUT   OUTDCB,=CL80'WE HAVE DELETED OLD TABLE'                  
         PUT   OUTDCB,=80C' '                                    
         B     DONE                                                    
         LTORG                                                          
***********INSERT STORAGE**************************************        
ISAVE    DS    7F                                                      
RSAVE    DS    F                                                        
***********DELETE SUBROUTINE***********************************        
DELTE    DS    0H                                                      
         STM   2,8,DSAVE                                                
         ST    11,DELTSAVE                                              
         LM    2,4,0(1)                                                
         L     6,0(0,2)                                                
         L     5,0(0,3)                                                
         L     7,0(0,4)                                                
         LTR   8,7                                                      
         BZ    FNSH                                                    
RPT1     ZAP   0(3,6),3(3,6)                                            
         LA    6,3(0,6)                                                
         BCT   6,RPT1                                                  
         DS    0H                                                      
         BCTR  7,0                                                      
         ST    7,0(0,4)                                                
         SRA   5,1(0)                                                  
         CR    7,5                                                      
         BL    DCR                                                      
FNSH     DS    0H                                                      
*                                                                      
         LM    2,8,DSAVE                                                
         L     11,DELTSAVE                                              
         BR    11                                                      
*                                                                      
DCR      DS    0H                                                      
         ST    5,TMPSIZE                                                
         LA    1,OBTMEM                                                
         BAL   11,ALCTE                                                
         PUT   OUTDCB,=80C' '                                          
         PUT   OUTDCB,=CL80'WE HAVE ALLOCATED NEW TABLE'                
         PUT   OUTDCB,=80C' '                                          
         PUT   OUTDCB,=CL80'WE HAVE DELETED OLD TABLE'                  
         PUT   OUTDCB,=80C' '                                          
         B     FNSH                                                    
***********DELETE STORAGE**************************************        
DSAVE    DS    7F                                                      
DELTSAVE DS    F                                                        
***************************************************************        
ALCTE    DS    0H                                                      
         STM   2,7,ASAVE                                                
         LM    2,5,0(1)                                                
         L     3,0(0,3)                                                
         L     5,0(0,5)                                                
         LR    7,3                                                      
         SR    6,6                                                      
         M     6,=F'3'                                                  
         STORAGE OBTAIN,LENGTH=(7),ADDR=TMPADD,COND=YES                
         LTR   15,15                                                    
         BZ    DOWN                                                    
         ABEND 123,DUMP                                                
DOWN     L     6,TMPADD                                                
         LR    7,3                                                      
BEGN     ZAP   0(3,6),=PL1'-1'                                          
         LA    6,3(0,6)                                                
         BCT   7,BEGN                                                  
         LTR   5,5                                                      
         BZ    JUMP                                                    
         L     6,TMPADD                                                
         L     7,0(0,2)                                                
DUPL     ZAP   0(3,6),0(3,7)                                            
         LA    6,3(0,6)                                                
         LA    7,3(0,7)                                                
         BCT   5,DUPL                                                  
JUMP     L     7,0(4)                                                  
         LTR   7,7                                                      
         BZ    SKIP                                                    
         L     7,0(0,2)                                                
         STORAGE RELEASE,LENGTH=(5),ADDR=(7)                            
SKIP     L     6,TMPADD                                                
         ST    6,0(2)                                                  
         ST    3,0(4)                                                  
*                                                                      
         LM    2,7,ASAVE                                                
         BR    11                                                      
         LTORG                                                          
************ALLOCATION STORAGE*********************************        
ASAVE    DS    6F                                                      
TMPADD   DS    F                                                        
************PRINT SUBROUTINE***********************************        
PRNT     DS    0H                                                      
         STM   2,5,PSAVE                                                
         LM    2,3,0(1)                                                
         PUT   OUTDCB,=80C' '                                          
         PUT   OUTDCB,=CL80'         NUMBERS LIST'                      
         PUT   OUTDCB,=80C' '                                          
         LA    4,OLINE                                                  
         SR    5,5                                                      
         L     2,0(0,2)                                                
         L     3,0(0,3)                                                
         LTR   3,3                                                      
         BZ    TOP1                                                    
AGAIN    DS    0H                                                      
         MVC   0(7,4),PAT                                              
         ED    0(7,4),0(2)                                              
         LA    2,3(0,2)                                                
         C     5,=F'4'                                                  
         BZ    NEXT1                                                    
         LA    4,8(0,4)                                                
         LA    5,1(0,5)                                                
         B     BOTTOM1                                                  
NEXT1    PUT   OUTDCB,OLINE                                            
         MVI   OLINE,C' '                                              
         MVC   OLINE+1(79),OLINE                                        
         LA    4,OLINE                                                  
         SR    5,5                                                      
BOTTOM1  BCT   3,AGAIN                                                  
*                                                                      
TOP1     PUT   OUTDCB,=80C' '                                          
         LM    2,5,PSAVE                                                
         BR    11                                                      
         LTORG                                                          
***********PRINT STORAGE***************************************        
PSAVE    DS    4F                                                      
OLINE    DC    80C' '                                                  
PAT      DC    X'40202020212060'                                        
***************************************************************        
         END   MAIN                                                    
/*                                                                      
//L.SYSLIB DD DSN=KC02293.SYS2.CALLIB,DISP=SHR                          
//G.INPUT  DD DSN=KC02314.SPRING16.CSCI641.HW4ADATA,DISP=SHR            
//G.OUTPUT DD DSN=&&TEMP,DISP=(NEW,PASS,DELETE)                        
//G.XSNAPOUT DD SYSOUT=*                                                
//G.XPRNT DD SYSOUT=*                                                  
//*                                                                    
//*                                                                    
//STEP2   EXEC PGM=IEBPTPCH                                            
//SYSTU1  DD DSN=&&TEMP,DISP=(OLD,DELETE)                              
//SYSTU2  DD SYSOUT=*                                                  
//SYSPRINT DD SYSOUT=*                                                  
//SYSIN    DD *                                                        
     PRINT MAXFLDS=1                                                    
     RECORD FIELD=(80)                                                  
/*                                                                      
//                                                                      
 



Thank, I really appreciate the help
pintu1228
 
Posts: 48
Joined: Mon Mar 23, 2015 12:41 am
Has thanked: 5 times
Been thanked: 0 time

Re: Using STORAGE macro with QSAM

Postby steve-myers » Wed Mar 23, 2016 5:52 am

Whatever gave you the idea this -
         GET   ADCB
         CLI   EOFFLAG,C'Y'
         BZ    xxx
         ...
EOFEXIT  MVI   EOFFLAG,C'Y'
         BR    14
         ...
ADCB     DCB   DSORG=PS,MACRF=GL,EODAD=EOFEXIT,...
EOFFLAG  DC    C' '
will work? I asked this before and you did not respond. Now, dammit, respond or else. Actually I found the clause in DFSMS Using Data Sets that says it will work most of the time, but not all the time, and why, but in 48 years I have never seen it done this way. You usually specify EODAD=xxx in the DCB macro.

A style issue. BZ and BE generate the same code, but you normally use something like BE, BNE, BL, BH, BNL or BNH after a comparison instruction like CLI, not BZ, which is usually used after a TM or an arithmetic instruction, and some other oddball instructions.
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: Using STORAGE macro with QSAM

Postby pintu1228 » Wed Mar 23, 2016 7:36 am

ok thanks I will take your suggestion on using BE instead of BZ after comparison instructions.
pintu1228
 
Posts: 48
Joined: Mon Mar 23, 2015 12:41 am
Has thanked: 5 times
Been thanked: 0 time

Re: Using STORAGE macro with QSAM

Postby pintu1228 » Fri Mar 25, 2016 4:58 am

As far as the rest of the code, how can I make the subroutines better and easier to follow? Is there a way to condense the code?
pintu1228
 
Posts: 48
Joined: Mon Mar 23, 2015 12:41 am
Has thanked: 5 times
Been thanked: 0 time

Re: Using STORAGE macro with QSAM

Postby willy jensen » Fri Mar 25, 2016 4:37 pm

Re structuring your program, look at 'Using structured programming macros' in 'High Level Assembler for z/OS & z/VM & z/VSE Toolkit Feature User’s Guide'. I does require that you have the feature installed. Note that using structured assembly macros are not to everyones liking - I use it a lot, I have had colleagues who hated it.
Or instead of

LOOP1    GET   INDCB,BUFFER            
         CLI   BUFFER,C'P'                                              
         BE    PRINTCLL                                                
         CLI   BUFFER,C'I'                                              
         BE    INSRTCLL                                                
 ...
         B     LOOP1
 

reverse your compares to something like this

LOOP1    GET   INDCB,BUFFER            
         CLI   BUFFER,C'P'                                              
         BNE   ENDTESTP                                                
* code for buffer = 'P'    
         B     LOOP1      
ENDTESTP  CNOP  0,4
         CLI   BUFFER,C'I'                                              
         BNE   ENDTESTI
* code for buffer = 'I'
         B     LOOP1
ENDTESTI  CNOP  0,4
         B     LOOP1
 

These users thanked the author willy jensen for the post:
pintu1228 (Fri Apr 01, 2016 1:10 am)
willy jensen
 
Posts: 455
Joined: Thu Mar 10, 2016 5:03 pm
Has thanked: 0 time
Been thanked: 69 times

Re: Using STORAGE macro with QSAM

Postby steve-myers » Thu Mar 31, 2016 11:48 pm

There are many ways to structure this. What I do is -
LOOP1    GET   INDCB,BUFFER
         CLI   BUFFER,C'P'
         BNE   TESTI
         ...
         B    LOOP1
TESTI    CLI   BUFFER,C'I'
         BNE   LOOP1
         ...
         B     LOOP1
Mr. Jenson's CNOP idea is good, but it is not a good idea to put a label on the CNOP. What I do is
LOOP1    GET   INDCB,BUFFER
         CLI   BUFFER,C'P'
         BNE   TESTI
         ...
         B     LOOP1
         CNOP  0,8
TESTI    CLI   BUFFER,C'I'
         BNE   LOOP1
         ...
         B     LOOP1
JES2 did this for a little while, but quit doing it – I don't know why. IMHO, CNOP 0,8 is usually better than CNOP 0,4. Most large machines fetch 8 bytes of storage at a time. When you use CNOP 0,4 the machine might fetch 8 bytes and then not use the first 4 bytes, depending on where in storage the CNOP 0,4 put the next instruction.

These users thanked the author steve-myers for the post:
pintu1228 (Fri Apr 01, 2016 1:10 am)
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: Using STORAGE macro with QSAM

Postby pintu1228 » Fri Apr 01, 2016 1:10 am

thanks, I was able to figure it out.
pintu1228
 
Posts: 48
Joined: Mon Mar 23, 2015 12:41 am
Has thanked: 5 times
Been thanked: 0 time

Re: Using STORAGE macro with QSAM

Postby willy jensen » Fri Apr 01, 2016 10:23 pm

@steve-mayers, except from the fact that the label might point to a bunch of '0700' and/or '4700' instructions, why wouldn't you use a label on the cnop instruction? I'm not disagreeing with you, just curious as to your reason. My example was from the top of my head to demonstrate a possible technique, it's not how I normally do it.
Willy
willy jensen
 
Posts: 455
Joined: Thu Mar 10, 2016 5:03 pm
Has thanked: 0 time
Been thanked: 69 times

Re: Using STORAGE macro with QSAM

Postby steve-myers » Fri Apr 01, 2016 11:17 pm

What's the point of executing NOPR and NOP instructions? Granted that they execute quickly, but why execute them at all? The other issue is fetching unused bytes because of unfavorable storage alignment. I raised this issue in my discussion of CNOP 0,4.

I usually insert a CNOP 0,8 before my internal subroutines, so the NOP instructions are not executed. Think about this
00055A 070047000700                2443          CNOP  0,8
The CNOP filled 6 bytes. HLASM generated what amounts to

BCR 0,0
BC 0,X'700'

Older Assemblers generated 3 NOPR 0 instructions.
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: Using STORAGE macro with QSAM

Postby willy jensen » Sat Apr 02, 2016 8:59 pm

ok, then we agree.
Willy
willy jensen
 
Posts: 455
Joined: Thu Mar 10, 2016 5:03 pm
Has thanked: 0 time
Been thanked: 69 times


Return to Assembler

 


  • Related topics
    Replies
    Views
    Last post