Sum of 10 numbers



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

Sum of 10 numbers

Postby tetra » Wed May 15, 2013 3:52 pm

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.. :(
tetra
 
Posts: 6
Joined: Wed May 15, 2013 3:43 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Sum of 10 numbers

 

Re: Sum of 10 numbers

Postby Robert Sample » Wed May 15, 2013 4:31 pm

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.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: Sum of 10 numbers

Postby steve-myers » Wed May 15, 2013 7:18 pm

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.
steve-myers
Global moderator
 
Posts: 1885
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 197 times

Re: Sum of 10 numbers

Postby tetra » Thu May 30, 2013 4:26 pm

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?
tetra
 
Posts: 6
Joined: Wed May 15, 2013 3:43 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Sum of 10 numbers

Postby NicC » Thu May 30, 2013 5:48 pm

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.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2690
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times

Re: Sum of 10 numbers

Postby Robert Sample » Thu May 30, 2013 6:08 pm

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.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: Sum of 10 numbers

Postby tetra » Thu May 30, 2013 6:43 pm

Ok, I understand you.
thanks
tetra
 
Posts: 6
Joined: Wed May 15, 2013 3:43 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Sum of 10 numbers

Postby steve-myers » Thu May 30, 2013 10:42 pm

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?
steve-myers
Global moderator
 
Posts: 1885
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 197 times

Re: Sum of 10 numbers

Postby tetra » Fri May 31, 2013 2:46 pm

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
tetra
 
Posts: 6
Joined: Wed May 15, 2013 3:43 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Sum of 10 numbers

Postby Robert Sample » Fri May 31, 2013 4:21 pm

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.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Next

Return to Assembler

 


  • Related topics
    Replies
    Views
    Last post