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'
HEADER DC CL20'XXXXXXXXXX'
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
* 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'
HEADER DC CL20'XXXXXXXXXX'
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
HELYMY
MY DSECT
DS 0F
X DS 1F
X2 DS 1F
X3 DS 1F
MEND
Here is my storage dump
Address Offset -------------- Data ---------------
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 ............
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 ............