home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 181.img / TASM-101.ZIP / CHAPXMPL.ARC / AVERAGE.ASM < prev    next >
Assembly Source File  |  1989-05-02  |  1KB  |  37 lines

  1. ;
  2. ; Turbo C-callable small-model function that returns the average
  3. ; of a set of integer values. Calls the Turbo C function
  4. ; IntDivide() to perform the final division.
  5. ;
  6. ; Function prototype:
  7. ;     extern float Average(int far * ValuePtr, int NumberOfValues);
  8. ;
  9. ; Input:
  10. ;     int far * ValuePtr:          ;the array of values to average
  11. ;     int NumberOfValues:          ;the number of values to average
  12.  
  13.         DOSSEG
  14.         .MODEL  SMALL
  15.         EXTRN   _IntDivide:PROC
  16.         .CODE
  17.         PUBLIC  _Average
  18. _Average        PROC
  19.         push    bp
  20.         mov     bp,sp
  21.         les     bx,[bp+4]          ;point ES:BX to array of values
  22.         mov     cx,[bp+8]          ;# of values to average
  23.         mov     ax,0               ;clear the running total
  24. AverageLoop:
  25.         add     ax,es:[bx]         ;add the current value
  26.         add     bx,2               ;point to the next value
  27.         loop    AverageLoop
  28.         push    WORD PTR [bp+8]    ;get back the number of values passed to
  29.                                    ; IntDivide as the rightmost    parameter
  30.         push    ax                 ;pass the total as the leftmost parameter
  31.         call    _IntDivide         ;calculate the floating-point average
  32.         add     sp,4               ;discard the parameters
  33.         pop     bp
  34.         ret                        ;the average is in the 8087's TOS register
  35. _Average        ENDP
  36.         END
  37.