home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / platform / llmul.asm < prev    next >
Assembly Source File  |  1998-06-17  |  3KB  |  99 lines

  1.         title   llmul - long multiply routine
  2. ;***
  3. ;llmul.asm - long multiply routine
  4. ;
  5. ;       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  6. ;
  7. ;Purpose:
  8. ;       Defines long multiply routine
  9. ;       Both signed and unsigned routines are the same, since multiply's
  10. ;       work out the same in 2's complement
  11. ;       creates the following routine:
  12. ;           __allmul
  13. ;
  14. ;*******************************************************************************
  15.  
  16.  
  17. .xlist
  18. include cruntime.inc
  19. include mm.inc
  20. .list
  21.  
  22. ;***
  23. ;llmul - long multiply routine
  24. ;
  25. ;Purpose:
  26. ;       Does a long multiply (same for signed/unsigned)
  27. ;       Parameters are not changed.
  28. ;
  29. ;Entry:
  30. ;       Parameters are passed on the stack:
  31. ;               1st pushed: multiplier (QWORD)
  32. ;               2nd pushed: multiplicand (QWORD)
  33. ;
  34. ;Exit:
  35. ;       EDX:EAX - product of multiplier and multiplicand
  36. ;       NOTE: parameters are removed from the stack
  37. ;
  38. ;Uses:
  39. ;       ECX
  40. ;
  41. ;Exceptions:
  42. ;
  43. ;*******************************************************************************
  44.  
  45.         CODESEG
  46.  
  47. _allmul PROC NEAR
  48.  
  49. A       EQU     [esp + 4]       ; stack address of a
  50. B       EQU     [esp + 12]      ; stack address of b
  51.  
  52. ;
  53. ;       AHI, BHI : upper 32 bits of A and B
  54. ;       ALO, BLO : lower 32 bits of A and B
  55. ;
  56. ;             ALO * BLO
  57. ;       ALO * BHI
  58. ; +     BLO * AHI
  59. ; ---------------------
  60. ;
  61.  
  62.         mov     eax,HIWORD(A)
  63.         mov     ecx,HIWORD(B)
  64.         or      ecx,eax         ;test for both hiwords zero.
  65.         mov     ecx,LOWORD(B)
  66.         jnz     short hard      ;both are zero, just mult ALO and BLO
  67.  
  68.         mov     eax,LOWORD(A)
  69.         mul     ecx
  70.  
  71.         ret     16              ; callee restores the stack
  72.  
  73. hard:
  74.         push    ebx
  75.  
  76. ; must redefine A and B since esp has been altered
  77.  
  78. A2      EQU     [esp + 8]       ; stack address of a
  79. B2      EQU     [esp + 16]      ; stack address of b
  80.  
  81.         mul     ecx             ;eax has AHI, ecx has BLO, so AHI * BLO
  82.         mov     ebx,eax         ;save result
  83.  
  84.         mov     eax,LOWORD(A2)
  85.         mul     dword ptr HIWORD(B2) ;ALO * BHI
  86.         add     ebx,eax         ;ebx = ((ALO * BHI) + (AHI * BLO))
  87.  
  88.         mov     eax,LOWORD(A2)  ;ecx = BLO
  89.         mul     ecx             ;so edx:eax = ALO*BLO
  90.         add     edx,ebx         ;now edx has all the LO*HI stuff
  91.  
  92.         pop     ebx
  93.  
  94.         ret     16              ; callee restores the stack
  95.  
  96. _allmul ENDP
  97.  
  98.         end
  99.