Page 1 of 2

Sum of 10 numbers

PostPosted: Wed May 15, 2013 3:52 pm
by tetra
Hello. I don't know what exactly wrong with my program. The task is summarize any 10 numbers by using ASSEMBLER in JCL(z/Os).
But in sdsf writes that smth wrong with my tags : NAME3, .. Name5..
//JOBTEST JOB ,'TESTASM1',MSGCLASS=H,MSGLEVEL=(1,1)
//STEP1 EXEC ASMAC                                       
//SYSIN DD *                                             
 START                                                                                         
BLR 7,0                                                                                         
NAME3 DC F'10'                                         
NAME4 DC F'0'                                         
NAME5 DC F'10'                                         
L 3, NAME3                                             
L 4, NAME4                                             
L 5, NAME5                                             
NEXTN AR 4,5                                           
AR 5,5
BCT 3,NEXTN 
 END             
 /*   


Help me, please.. :(

Re: Sum of 10 numbers

PostPosted: Wed May 15, 2013 4:31 pm
by Robert Sample
1. Assembler variable definitions cannot (generally) be executed; you need to move them somewhere in your code that they won't be executed.
2. You did not establish addressability to your code.

Re: Sum of 10 numbers

PostPosted: Wed May 15, 2013 7:18 pm
by steve-myers
Mr. Sample hit several high spots; I will add more.
  • The very first thing all MVS Assembler programs must do is save the registers. When the operating system calls your program, register 13 contains the address of a 72 byte data area for this purpose.
  • BLR 7,0
    1. labels must start in column 1, Your BLR is a label, not an instruction. In any event ...
    2. There is no BLR in the instruction set. I presume you intended to use BALR.

      BALR reg,0 stores the address of the next instruction in the register.
  • Your code to do the sum does not make much sense. Only the L 3, NAME3 is useful. Usually it would be followed by A 3,NAME4 and so on.
  • NEXTN AR 4,5
    AR 5,5
    BCT 3,NEXTN

    This sequence does not make much sense, either. The BCT 3,NEXTN instruction is often used to establish a loop. but you are initializing register 3 with the first value. Normally it would be initialized to number of times the loop is to execute.

    In the second line, AR is a label, not an instruction.
  • There is nothing following the BCT instruction. Unlike many high level languages, where there is nothing after the last instruction it implies the program is to exit, in Assembler you must insert code to exit. The code is not there.

Re: Sum of 10 numbers

PostPosted: Thu May 30, 2013 4:26 pm
by tetra
ok, thanks.

Now I get this code.
//JOBTEST JOB ,'ASM1',MSGCLASS=H,MSGLEVEL=(1,1)
//STEP1 EXEC ASMACLG                           
//SYSIN DD *                                   
EX1   START                                     
        BALR     12,0                             
        USING    *,12                             
        L        3,NUM                           
        SR       4,4                             
        SR       2,2                             
        L        2,SUM                           
LAB1    A        2,X(4)                           
        A        4, INDEX                         
        BCT      3,LAB1                           
INDEX   DC       F'4'                             
NUM     DC       F'10'                           
SUM     DC       F'0'                             
X       DC       F'10,20,30,40,50,60,70,80,90,100'
        END      EX1
 /*                 


BUT SDSF writes
IEA995I SYMPTOM DUMP OUTPUT 349
SYSTEM COMPLETION CODE=0C1 REASON CODE=00000001

Where is the mistake?

Re: Sum of 10 numbers

PostPosted: Thu May 30, 2013 5:48 pm
by NicC
Have you looked up the messages and codes manual to read about the error. From that you can start to look in the program yourself and , along with your notes/books/manuals you can possibly work out what is wrong. You cannot rely on people to tell you what is wrong for the rest of your life so get used to at least trying from day 1.

Re: Sum of 10 numbers

PostPosted: Thu May 30, 2013 6:08 pm
by Robert Sample
As I stated in my earlier post, data does not execute well. You need some instructions after the BCT instruction to exit your program before you start defining data. In a NORMAL Assembler program, that would consist of restoring the registers using the save area and then returning to the calling program.

Re: Sum of 10 numbers

PostPosted: Thu May 30, 2013 6:43 pm
by tetra
Ok, I understand you.
thanks

Re: Sum of 10 numbers

PostPosted: Thu May 30, 2013 10:42 pm
by steve-myers
Subject to Mr. Sample's comments, it looks good to me.

The primary reason to use Assembler is Assembler programs can execute faster than comparable compiled programs. To do this, you, as a programmer, must understand how the machine works. One fundamental rule you should never forget is storage access is much slower (and sometimes much, much slower) than the rest of the machine. Your A 4,INDEX can be done more quickly. There are at least 3 ways it can be done more quickly. Tell us at least one way.

Another rule relates to the derivation of constants. Internal IBM coding rules are quite explicit about this. Your program has NUM DC F'10'. The 10 is the number of elements in X. If you change the number of entries in X, you have to change the value in NUM. There is a better way:
INDEX    DC    A(L'X)
NUM      DC    A(XSIZE)
X        DC    F'1,2,3'
XSIZE    EQU   (*-X)/L'X
L'X tells the Assembler to use the number of bytes in the first element of X. (*-X) tells the Assembler to compute the number of bytes between the current value of the location counter and the value of the location counter for X. So what will be the value of XSIZE?

You have

SR 2,2
L 2,SUM

What's the point of the SR?

Re: Sum of 10 numbers

PostPosted: Fri May 31, 2013 2:46 pm
by tetra
To steve-myers

About ways to do more quickly, may be they are
1. Use register for INDEX(for example register 5), and organize sum between registers AR 4, 5
2. Using register and constant value
3. Something like using macro

It's interesting way, that you show. But the task is to summarize only 10 numbers.

SR 2,2 - It's like doing the zero in register 2
L 2,SUM

Re: Sum of 10 numbers

PostPosted: Fri May 31, 2013 4:21 pm
by Robert Sample
SR 2,2 - It's like doing the zero in register 2
L 2,SUM
The point you are missing is that the L instruction completely replaces the contents of register 2, so why do the SR in the first place?

Your list of speed improvements did not include the LA instruction, but it should.