home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 1.ddi / CLIBSRC1.ZIP / F_LXMUL.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-06-10  |  1.9 KB  |  64 lines

  1. ;[]-----------------------------------------------------------------[]
  2. ;|      F_LXMUL.ASM -- long multiply routine                         |
  3. ;[]-----------------------------------------------------------------[]
  4.  
  5. ;
  6. ;       C/C++ Run Time Library - Version 5.0
  7. ;       Copyright (c) 1987, 1992 by Borland International
  8. ;       All Rights Reserved.
  9.  
  10.         INCLUDE RULES.ASI
  11.  
  12. ; calls to this routine are generated by the compiler to perform
  13. ; long multiplications.
  14.  
  15. ; There is no check for overflow.  Consequently, the same routine
  16. ; is used for both signed and unsigned long multiplies.
  17.  
  18. ;
  19. ; in:
  20. ;       (dx:ax) - 32bit arg1
  21. ;       (cx:bx) - 32bit arg2
  22. ; out:
  23. ;       (dx:ax) - 32bit product
  24. ;
  25. ; reg use: bx,cx destroyed, all others preserved or contain result.
  26. ;
  27. ; hi(result) := lo(hi(arg1) * lo(arg2)) +
  28. ;               lo(hi(arg2) * lo(arg1)) +
  29. ;               hi(lo(arg1) * lo(arg2))
  30. ; lo(result) := lo(lo(arg1) * lo(arg2))
  31. ;
  32. ;
  33. _TEXT   SEGMENT BYTE PUBLIC 'CODE'
  34.         ASSUME  CS:_TEXT
  35.  
  36.         public  LXMUL@
  37.         public  F_LXMUL@
  38.  
  39. LXMUL@          PROC    FAR
  40. F_LXMUL@:
  41.                 push    si
  42.                 xchg    si,ax           ; save lo1
  43.                 xchg    ax,dx
  44.                 test    ax,ax           ; skip mul if hi1==0
  45.                 jz      nohi1
  46.                 mul     bx              ; hi1 * lo2
  47.  
  48. nohi1:          ; if we jumped here, ax==0 so the following swap works
  49.                 jcxz    nohi2           ; skip mul if hi2==0
  50.                 xchg    cx, ax          ; result <-> hi2
  51.                 mul     si              ; lo1 * hi2
  52.                 add     ax, cx          ; ax = hi1*lo2 + hi2*lo1
  53. nohi2:
  54.                 xchg    ax,si
  55.                 mul     bx              ; lo1 * lo2
  56.                 add     dx,si           ; hi order result += partials
  57.                 pop     si
  58.                 ret
  59. LXMUL@          ENDP
  60. _TEXT   ENDS
  61.         END
  62.