.TITLE Average Version 9 ; This program will calculate the average of a set of ; numbers and store the result in the location Ave. ; The first data item must be the size of the set ; followed by the data values to average over Size: .WORD 5 ;Number of data points Data: .WORD 2776 ;First data point .WORD 2167 ;Second data point .WORD 133 ;Third data point .WORD 512 ;Fourth data point .WORD 24 ;Fifth data point Ave: .BLKW 1 ;Save room for the answer .ENTRY AVERAGE, 0 MOVW Size, R3 ;Initialize R3 to data set size CLRW R5 ;Initialize sum in R5 to 0 CLRL R4 ;Initialize index register to 0 MOVAW Data, R6 ;Initialize R6 to data base ; address Next: TSTW R3 ;Any data left? BEQL Done ;If R3=0, go to Done ADDW2 (R6)[R4], R5 ;R5 contains the current sum INCL R4 ;Add one to the index DECW R3 ;Decrease the count by one BRB Next ;Add next data item to the list Done: DIVW3 Size, R5, Ave ;Ave contains R5/Size $EXIT_S .END AVERAGE