; ; This program is written in simplified IBM mainframe assembly ; language (BAL) ; ; The program opens the file SCORES.FILE and reads 15-byte records ; into the array ARRAY. Each record consists of a 12-byte name and ; a 3-byte number (a bowling score). The program calculates the ; average of all the scores read into the array. It then examines ; the array and for each record that contains the average score ; writes the name to the file AVERAGE.FOLKS ; CSECT ;Make entry, show expansion OPEN IN,IFID,15,R ;Open input file L 3,=F'0' ;Count records in reg 3 L 8,ADDR ;Set up moving records LOOP: GET IFID,ERR ;Read a record, go to ERR on EOF MVC 0(15,8),IFID_BUF ;Move record - buffer to array A 8,SIZE A 3,=F'1' ;Count the record B LOOP ERR: ST 3,COUNT ;Save record count in COUNT CLOSE IFID ;Close input file L 5,=F'0' ;Accumulate sum in reg 5 L 4,ADDR ;Set up record access AGAIN: PACK PDEC(8),12(3,4) ;Convert score to packed dec. CVB 6,PDEC ;Convert packed to binary AR 5,6 ;Add score to sum A 4,SIZE S 3,=F'1' ;Count down for control loop BP AGAIN D 4,COUNT ;Compute average in reg 5 L 3,COUNT ;Set up counter for loop (reg 3) L 8,ADDR ;Set up record access OPEN OUT,OFID,12,W ;Open output file LAST: PACK PDEC(8),12(3,8) ;Convert score to packed dec. CVB 7,PDEC ;Convert packed to binary CR 7,5 ;Compare score with average BNE HOP ;Check for equality MVC OFID_BUF(12),0(8) ;On equal, move name to buffer PUT OFID ;Write name to output file HOP: A 8,SIZE S 3,=F'1' ;Count down for loop control BP LAST CLOSE OFID ;Close output file BR 14 ;Terminate program IN: DC F'11' ;Length of input file name DC C'SCORES.FILE' ;Input file name OUT: DC F'13' ;Length of output file name DC C'AVERAGE.FOLKS' ;Output file name ADDR: DC A'ARRAY' ;Address of array ARRAY: DS 1500C ;Storage for up to 100 records PDEC: DS 2F ;Packed decimal storage COUNT: DS 1F ;Record count SIZE: DC F'15' ;Input record size END