home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / BASIC / POWBASIC / LIBRARY1 / EXAMP1.ZIP / UMEX301.ASM < prev    next >
Assembly Source File  |  1990-03-29  |  1KB  |  38 lines

  1. ; User's Manual Example, Page 301.
  2. ;
  3. ; Changed name from "sum.asm" to "umex301.asm"
  4. ; Relates to "umex300.bas".
  5.  
  6. code          segment byte
  7.           assume      cs:code
  8.  
  9. ; si,di,ds,bp,sp,ss must be preserved
  10. ; long integer result is returned in dx:ax
  11.  
  12. suminteger    proc        far
  13.           public      suminteger
  14.  
  15.           push bp                 ;bp must be preserved
  16.           mov  bp, sp             ;create a parameter stack frame
  17.           push ds                 ;ds must be preserved
  18.           xor  ax, ax             ;zero the low-order result
  19.           xor  dx, dx             ;zero the high-order result
  20.           lds  bx, [bp] [06]      ;get a pointer to the count
  21.           mov  cx, [bx]           ;cx = count of array elements
  22.           lds  bx, [bp] [10]      ;ds:[bx] = pointer to first element
  23.  
  24.           jcxz sum2               ;in case of zero elements
  25. sum1:
  26.           add  ax, ds:[bx]        ;add in one integer
  27.           adc  dx, 0              ;account for possible integer overflow
  28.  
  29.           add  bx, 2              ;point to the next integer
  30.           loop sum1               ;repeat as necessary
  31. sum2:
  32.           pop  ds                 ;restore the caller's registar
  33.           pop  bp
  34.           retf 8                  ;clear 8 bytes of parameters
  35.  
  36. suminteger    endp
  37. code          ends
  38.           end