AVG/SALARY: [ R1, R2 -> R0 ] [ R27 ] [/ R3..R9 /]

        R       R3, R1, R27, TRAP_ON_ERROR;                          /* R3 = pointer_from (R1), R27 or trap ();  */

        RR/I    R0, SET_WRITE;                                       /* R0 = 0, write-first;                     */
        RR/I    R3..R9, SET_READ_WRITE;                              /* R3..R9 = 0, read-write;                  */



DO:     DO      R4, R2, .NEXT;                                       /* do (R4 = 0) while ([< R2], R4) {         */

                ADDPTR/T R5,                                         /*     R5 = &(                              */
                             R3, SIZE_OF/STRUCT/SALARY, R4,          /*             R3 + R4 * size_of (Salary)   */
                             STRUCT/SALARY/FIELD_OFFSET/LEVEL;       /*           )->Level;                      */
                      
                LOAD R6, R5, DT_DWORD;                               /*     R6 = ^R5;                            */

                ADDPTR/T R5,                                         /*     R5 = &(                              */
                             R3, SIZE_OF/STRUCT/SALARY, R4,          /*             R3 + R4 * size_of (Salary)   */
                             STRUCT/SALARY/FIELD_OFFSET/QUANTITY;    /*           )->Quantity;                   */
                      
                LOAD R7, R5, DT_DWORD;                               /*     R7 = ^R5;                            */

                MUL R6, R7;                                          /*     (* R7), R6;                          */
                ADD R8, R6;                                          /*     (+ R6), R8;                          */

                ADD R9, R7;                                          /*     (+ R7), R9;                          */

NEXT:   NEXT    R4, R2;                                              /* } next (R4 ++) if ([< R2], R4);          */



IF:     BZ R9 ->.END;                                                /* if (![= 0], R9) {                        */

                DIV     R0, R8, R9;                                  /*     R0 = (/ R9), R8;                     */
                ROUND   R0;                                          /*     R0 = round (R0);                     */

END:    ;                                                            /* }                                        */



        RR/HIDE R3..R9;                                              /* R3..R9 = 0, no-access;                   */

RET
