Page 1 of 1

S0C1 abend when adding numbers in an array

PostPosted: Tue Jan 17, 2017 9:20 am
by monica1
Hi,

I am trying to work on an array program to understand the concepts of array processing in Assembler.

Given below is the array program to add the numbers in an array.

* ADD NUMBERS IN AN ARRAY        
ADDARR   CSECT                    
         BALR 12,0                
         USING *,12              
         USING TNUMSECT,6        
         BAL 11,ADDRTN            
         WTO 'DISPLAY1'          
         OPEN (OUTDCB,(OUTPUT))  
         UNPK OUTNUM,TOT          
         OI OUTNUM+1,X'F0'        
         PUT OUTDCB,OUTAREA      
         WTO 'DISPLAY9'          
         CLOSE (OUTDCB)          
         B EXIT                  
ADDRTN   ST 11,ADDSAVE            
         WTO 'DISPLAY2'          
         LA 6,TNUMTABL        
         LA 3,ENUM#ENT        
MOREENT  DS 0H                
         WTO 'DISPLAY3'      
         AP TOT,TNUMCODE      
         LA 6,ENUMLEN(,6)    
         BCT 3,MOREENT        
ADDEXIT  DS 0H                
         WTO 'DISPLAY4'      
         L 11,ADDSAVE        
         BR 11                
EXIT     L 13,SAVE+4          
         WTO 'DISPLAY10'      
         LM 14,12,12(13)      
         WTO 'DISPLAY11'      
         XR 15,15            
         WTO 'DISPLAY12'      
         BR 14                                                          
         WTO 'DISPLAY13'                                                
* DECLARATIONS                                                          
ADDSAVE  DC F'0'                                                        
SAVE     DS 18F                                                        
TOT      DC PL2'0'                                                      
OUTDCB   DCB DSORG=PS,MACRF=(PM),DDNAME=TESTOUT,                       X
               RECFM=FB,LRECL=80,BLKSIZE=0                              
OUTAREA  DS 0CL80                                                      
OUTNUM   DS CL2                                                        
FILLER1  DS CL78' '                                                    
* TABLE DECLARATION                                                    
TNUMTABL DS 0H                                                          
         DC PL2'15'                                                    
ENUMLEN  EQU (*-TNUMTABL)                                              
         DC PL2'12'                                                    
         DC PL2'09'                                                    
         DC PL2'16'                  
         DC PL2'05'                  
ENUMTLEN EQU (*-TNUMTABL)            
ENUM#ENT EQU (ENUMTLEN/ENUMLEN)      
* DSECT ENTRY FOR TABLE              
TNUMSECT DSECT                      
TNUMENTY DS 0PL2                    
TNUMCODE DS PL2                      
ENUMENTY EQU (*-TNUMSECT)            
         END


When I am running this program, I am able to see the result in the output file but the job abends with S0C1 abend.

Below is the output file.

****** ***************************** Top of Data ******************************
000001 57                                                                      
****** **************************** Bottom of Data ****************************


I am able to see the display till DISPLAY10 in spool but not able to see the displays later on which means there is a problem with the statement LM 14,12,12(13) .

Could you help me out in understanding if we need to add anything specific when working with arrays?

Thank you.

Re: S0C1 abend when adding numbers in an array

PostPosted: Tue Jan 17, 2017 9:34 am
by steve-myers
I hope you realized WTO will alter registers 14 through 1.

In general, you should assume all macros will alter registers 14, 15, 0 and 1

Re: S0C1 abend when adding numbers in an array

PostPosted: Tue Jan 17, 2017 9:52 am
by monica1
I used WTO to understand how the control is flowing and where exactly the error is coming up. Is there any other way other than WTO inorder to debug the program without altering the register contents?

Re: S0C1 abend when adding numbers in an array

PostPosted: Tue Jan 17, 2017 10:08 am
by Robert Sample
Is there any other way other than WTO inorder to debug the program without altering the register contents?
The SNAP macro allows you to print memory locations and / or registers to an output file.

Re: S0C1 abend when adding numbers in an array

PostPosted: Tue Jan 17, 2017 10:08 am
by prino
monica1 wrote:I used WTO to understand how the control is flowing and where exactly the error is coming up. Is there any other way other than WTO inorder to debug the program without altering the register contents?

Use IBM's Debug Tool.

Re: S0C1 abend when adding numbers in an array

PostPosted: Tue Jan 17, 2017 10:30 am
by steve-myers
Most shops discourage the use of WTO as you're using it to track program flow. There are simply too many totally useless messages flooding operator consoles for operators to pick out important messages.

Look at what happens with this sequence

WTO 'RESTORING REGISTERS'
L 13,4(,13)
LM 14,12,12(13)
WTO 'RETURNING
SR 15,15
BR 14

Now, look at the expansion of WTO 'RETURNING'

BAL 1,*+18
DC AL2(13,0),C'RETURNING'
DC 0H'0'
SVC 35

The purpose of the BAL instruction is to store the address of the message into register 1. The message starts with the DC AL2... instruction. It also branches to the next instruction to execute, the SVC 35 instruction. BAL is an RX type instruction, which means it uses a base register. Well, guess what? the LM 14,12 just wiped out your base register, so it's rather hard to predict where the BAL will actually branch to.

By the way, I invented the expansion, but it's probably pretty close to the real expansion.

OS/360 had a batch facility called Testtran for batch debugging. It was hard to use, and really not that useful. IBM killed Testtran when they added TSO, and turned the Testtran break in facility over to TSO for TSO TEST. TSO TEST, which lets you test most unauthorized programs from your TSO terminal has many flaws, but after you learn it you will rarely test a program in batch

Re: S0C1 abend when adding numbers in an array

PostPosted: Tue Jan 17, 2017 11:31 am
by monica1
I had missed to include the below statements at the beginning of the program.

STM 14,12,12(13)

ST 13,SAVE+4
LA 13,SAVE

Screenshot of how I included these in the program is shown below.

* ADD NUMBERS IN AN ARRAY                
ADDARR   CSECT                          
         STM 14,12,12(13)                
         BALR 12,0                      
         USING *,12                      
         USING TNUMSECT,6                
         ST 13,SAVE+4                    
         LA 13,SAVE                      
MAINPGM  OPEN (OUTDCB,(OUTPUT))


Once these instructions were added, the program ran fine.

Thanks everyone for your help.