## INTERMEDIAT VALUE IN STORAGE DUMP

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

### INTERMEDIAT VALUE IN STORAGE DUMP

This is my assignment question.
Loop from -4 to 5 using immediate instructions, not from loading predefined values from data area. In that loop calculate the square of the loop counter(i.e. x2) as well as its cube (i.e. X3). Store the loop counter value, its square, and its cube in data areas fall all 10 iterations. Compute three average: the average of the loop counter values, of the squares, and of the cubes, storing these as well. Be sure to account for rounding. Use mapping macro for each set of x,x2, and x3 values.

I am almost done with my code and getting results as expected. The only issue I am having is seeing intermediate values of X2 and X3. I can see the intermediate value of X (highlighted in red) but not for x2 and x3.

Here is my code,
***************************************************************
*   BEGIN
*************************************************************
LA    R9,MYSPACE
USING MY,R9
LA    R9,RESULTS
LA    R2,X               X
SR    R3,R3              SUM OF ALL Xs
LA    R4,X2              X2
SR    R5,R5              SUM OF ALL X2s
LA    R6,X3              X3
SR    R7,R7              SUM OF ALL X3s
LHI   R8,-4              SETTING LOOP COUNTER INIT VALUE
*   R12 NOT USED
STARTLOP EQU   *
SR    R10,R10
LR    R11,R8
ST    R11,0(R2)
A     R9,=F'4'
AR    R3,R11
MR    R10,R8             SQUARING X
ST    R11,0(R4)
A     R9,=F'4'
AR    R5,R11
MR    R10,R8             CUBING X
ST    R11,0(R6)
A     R9,=F'4'
AR    R7,R11
AHI   R8,1
A     R2,=F'4'            INCREMENTING 4 BYTES = FULLWORD
A     R4,=F'4'            INCREMENTING 4 BYTES = FULLWORD
A     R6,=F'4'            INCREMENTING 4 BYTES = FULLWORD
C     R8,=F'5'
BNH   STARTLOP
B     CALCAVG
CALCAVG  EQU   *
ST    R3,0(R9)
A     R9,=F'4'
ST    R5,0(R9)
A     R9,=F'4'
ST    R7,0(R9)
A     R9,=F'4'
SR    R2,R2               INITIALIZE REG FOR REMAINDER
D     R2,=F'10'           CALCULATE AVERAGE OF COUNTSUM
C     R2,=F'5'            COMPARE R2 AND 5
BNL   RNDCOUNT            IF NOT LOWER THAN 5
ST    R3,AVGX
CALCSQRE EQU   *               INITIALIZE REG FOR REMAINDER
SR    R4,R4
D     R4,=F'10'           CALCULATE AVERAGE OF SQURESUM
C     R4,=F'5'            COMPARE R4 AND 5
BNL   RNDSQURE            IF NOT LOWER THAN 5
ST    R3,AVGX2
CALCCUBE EQU   *                   INITIALIZE REG FOR REMAINDER
SR    R6,R6
D     R6,=F'10'           CALCULATE AVERAGE OF CUBESSUM
C     R6,=F'5'            COMPARE R6 AND 5
BNL   RNDCUBES            IF NOT LOWER THAN 5
ST    R3,AVGX3
RNDCOUNT EQU   *
AHI   R3,1
ST    R3,AVGX
B     CALCSQRE
RNDSQURE EQU   *
AHI   R5,1
ST    R5,AVGX2
B     CALCCUBE
RNDCUBES EQU   *
AHI   R7,1
ST    R7,AVGX3
DC    H'0'
B     RETURN
*************************************************************
*   END LOGIC HERE
************************************************************
********************* DATA AREAS *********************
SAVEAREA DC     16F'0'
RESULTS  DS     33F
*SUMX     DS     1F
*SUMX2    DS     1F
*SUMX3    DS     1F
AVGX     DS     1F
AVGX2    DS     1F
AVGX3    DS     1F
MYSPACE  DS     100F
HELYMY

Macro
MACRO
HELYMY
MY       DSECT
DS     0F
X        DS     1F
X2       DS     1F
X3       DS     1F
MEND

Here is my storage dump

00007D60 +000E0  C1D20000 47F0C0E2 58D0C0F6 58ED000C  AK...0.S...6....
00007D70 +000F0  981CD014 07FE0000 00000000 00006F60  q.............?-
00007D80 +00100  00000000 00000000 00000000 00000000  ................
LINES 00007D90-00007DA0 SAME AS ABOVE
00007DB0 +00130  00000000 00000000 C3E4C2C5 E2C4C1E3  ........XXXXXX
00007DC0 +00140  C1404040 40404040 40404040 [color=#FF0000]FFFFFFFC[/color]  X           ....
00007DD0 +00150  [color=#FF0000]FFFFFFFD FFFFFFFE FFFFFFFF 00000000[/color]  ................
00007DE0 +00160  [color=#FF0000]00000001 00000002 00000003 00000004[/color]  ................
00007DF0 +00170  [color=#FF0000]00000005[/color] 00000019 0000007D 00000000  ...........'....
00007E00 +00180  00000000 00000000 00000000 00000000  ................
LINES 00007E10-00007E30 SAME AS ABOVE
00007E40 +001C0  00000000 00000005 00000055 0000007D  ...............'
00007E50 +001D0  00000001 00000009 0000000D 00000000  ................
00007E60 +001E0  00000000 00000000 00000000 00000000  ................
LINES 00007E70-00007FE0 SAME AS ABOVE
00007FF0 +00370  00000004 00000005 0000000A           ............

xboss

Posts: 79
Joined: Mon Nov 29, 2010 10:55 am
Has thanked: 0 time
Been thanked: 0 time

### Re: INTERMEDIAT VALUE IN STORAGE DUMP

Sorry color didn't work inside code element. I appreciate your time looking into my code.

Thanks.
xboss

Posts: 79
Joined: Mon Nov 29, 2010 10:55 am
Has thanked: 0 time
Been thanked: 0 time

### Re: INTERMEDIAT VALUE IN STORAGE DUMP

On a quick look, you are overwriting each square and cube except the final one. Five squared is 25, X'00000019' and five cubed is 125, X'0000007D'.

You are storing result1, result2, result3, then in the next loop putting result4 over result2, result5 over result3, and result6 in an empty location. Then in the next loop putting result7 over result3, result8 over result4 and result9 over result4. etc through each iteration.

There are several ways to fix it. Have a go, and let us know the result.
BillyBoyo
Global moderator

Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

### Re: INTERMEDIAT VALUE IN STORAGE DUMP

Thanks Billy for you time looking into my problem and replying. Yes, I knew the problem that it is over riding the last two value every time it is looping but I don't know why since I have incremented register by 4bytes (1 Fullword) every time in the loop. Can you explain me please?
Yes I did solve the problem but with different approaches. One way of doing is listed below. Everything is same except STARTLOP portion (code is listed below. But still interested why it is over riding?
STARTLOP EQU   *
SR    R10,R10
LR    R11,R8
LR    R2,R11
ST    R2,0(R9)
A     R9,=F'4'
AR    R3,R11
MR    R10,R8
LR    R4,R11
ST    R4,0(R9)
A     R9,=F'4'
AR    R5,R11
MR    R10,R8
LR    R6,R11
ST    R6,0(R9)
A     R9,=F'4'
AR    R7,R11
AHI   R8,1
C     R8,=F'5'
BNH   STARTLOP
B     CALCAVG

Once again thanks for looking into it.
xboss

Posts: 79
Joined: Mon Nov 29, 2010 10:55 am
Has thanked: 0 time
Been thanked: 0 time

### Re: INTERMEDIAT VALUE IN STORAGE DUMP

In your macro you define your storage areas X, X1, and X2 as adjacent to each other. Each is a fullword. When you increment the address of X by four bytes, it points to X then points to the location of X1, containing your first square. You increment X1 by four bytes, then it points to the location of X2,

This happens each time through the loop. One way would be to increment by 12 for each. Another way would be to seperate, in the macro definition, X, X1 and X2 so that they are 10 fullwords apart.
BillyBoyo
Global moderator

Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

### Re: INTERMEDIAT VALUE IN STORAGE DUMP

In a nutshell, I had a wrong concept regarding storage allocation. I got a clear picture now. Thank you so much Billy.
xboss

Posts: 79
Joined: Mon Nov 29, 2010 10:55 am
Has thanked: 0 time
Been thanked: 0 time

### Re: INTERMEDIAT VALUE IN STORAGE DUMP

No problem. I suspect you thought the data was "in" the registers somehow. But all the registers in this example were doing was pointing to storage four bytes apart.
BillyBoyo
Global moderator

Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

### Re: INTERMEDIAT VALUE IN STORAGE DUMP

Thats right, Bill.
xboss

Posts: 79
Joined: Mon Nov 29, 2010 10:55 am
Has thanked: 0 time
Been thanked: 0 time