home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 9.ddi / CHAPXMPL.ZIP / AVERAGE.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-02-13  |  1.6 KB  |  43 lines

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