This
will not work. I mainly doctored it to correct some of the issues Mr. Sample noted, particularly point 1. It does assemble cleanly. My little sample a couple of posts back uses a slightly different method to establish the array limits.
Mr. Sample's concern about the use of register 1 is something you should remember, but is not significant in your code. Any time you use an IBM macro you must assume registers 0, 1, 14 and 15 are going to be trashed. Most of my code uses these registers as short term work registers quite heavily. In most of my programs register 1 or register 15 is the most frequently referenced register. In a program I've been working on these last 2 weeks, a little over 1000 lines, register 1 has 158 references and register 15 has 206 references. The next most used register has 91 references.
Anyway, here is your doctored program -
TITLE 'SCORE ARRAY SCALER'
EX2 CSECT
R12 EQU 12 BASE REGISTER
R13 EQU 13 SAVE AREA POINTER
R14 EQU 14 RETURN REGISTER
* STANDARD ENTRY AND INITIALIZATION:
STM R14,R12,12(R13) SAVE REGISTERS
BALR R12,0 LOAD BASE REGISTER
USING BASE,R12 DECLARE BASE ADDRESS AND REGISTER
BASE ST R13,SAVE+4 SAVE R13
LA R13,SAVE R13 = ADDRESS OF SAVE AREA
* BEGIN PROCESSING ARRAY
L 7,LIMIT
LA 6,COUNT
LOOP2 LA 1,0
LA 4,L'ARRAY
LOOP L 2,ARRAY(1)
L 3,ARRAY(4)
CR 2,3
BNH SKIP
ST 2,ARRAY(4)
ST 3,ARRAY(1)
SKIP A 1,FOUR
A 4,FOUR
C 4,LIMIT
BL LOOP
S 7,FOUR
BCT 6,LOOP2
* STANDARD EXIT:
DONE L R13,SAVE+4 RESTORE R13
LM R14,R12,12(R13) RESTORE REGISTERS
BR R14 RETURN
* STORAGE:
ARRAY DC F'3'
DC F'12'
DC F'9'
DC F'23'
DC F'99'
COUNT EQU (*-ARRAY)/L'ARRAY
FOUR DC A(L'ARRAY)
LIMIT DC A(L'ARRAY*COUNT)
SAVE DS 18F
END EX2
Another thing about this code is the use of Assembler derived values. For example -
COUNT EQU (*-ARRAY)/L'ARRAY
*-ARRAY computes the number of bytes between the current value of the location counter and the value assigned to ARRAY; L'ARRAY directs the Assembler to use the length attribute of ARRAY. So COUNT is the number of words in ARRAY. Add another word, and the Assembler updates COUNT automatically. You see essentially the same thing in C from time to time:
int array[] = {3, 12, 9, 23, 99};
int count = sizeof(array) / sizeof(array[0]);
Mr. Sample's point 4 talks about replacing A 4,FOUR with LA 4,4(,0,4) to eliminate a storage reference. Storage, relative to computer instruction processing rate is s-l-o-w. In the 1990s, IBM added the first of the immediate instructions because they finally realized storage is s-l-o-w, though LA has been used for this purpose by Assembler guys for more than 40 years in spite of serious problems that have caught programmers by surprise more than once. Today we might use AHI 4,4 rather than LA. In the last 10 years IBM has added immediate instructions with 32 bit operands though most of us use them infrequently, if at all.