Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.5 KiB

  1. title llmul - long multiply routine
  2. ;***
  3. ;llmul.asm - long multiply routine
  4. ;
  5. ; Copyright (c) 1985-2001, 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. ;Revision History:
  15. ; 11-29-83 DFW initial version
  16. ; 06-01-84 RN modified to use cmacros
  17. ; 04-17-85 TC ignore signs since they take care of themselves
  18. ; do a fast multiply if both hiwords of arguments are 0
  19. ; 10-10-86 MH slightly faster implementation, for 0 in upper words
  20. ; 03-20-89 SKS Remove redundant "MOV SP,BP" from epilogs
  21. ; 05-18-89 SKS Preserve BX
  22. ; 11-28-89 GJF Fixed copyright
  23. ; 11-19-93 SMK Modified to work on 64 bit integers
  24. ; 01-17-94 GJF Minor changes to build with NT's masm386.
  25. ; 07-22-94 GJF Use esp-relative addressing for args. Shortened
  26. ; conditional jump.
  27. ;
  28. ;*******************************************************************************
  29. .xlist
  30. include cruntime.inc
  31. include mm.inc
  32. .list
  33. ;***
  34. ;llmul - long multiply routine
  35. ;
  36. ;Purpose:
  37. ; Does a long multiply (same for signed/unsigned)
  38. ; Parameters are not changed.
  39. ;
  40. ;Entry:
  41. ; Parameters are passed on the stack:
  42. ; 1st pushed: multiplier (QWORD)
  43. ; 2nd pushed: multiplicand (QWORD)
  44. ;
  45. ;Exit:
  46. ; EDX:EAX - product of multiplier and multiplicand
  47. ; NOTE: parameters are removed from the stack
  48. ;
  49. ;Uses:
  50. ; ECX
  51. ;
  52. ;Exceptions:
  53. ;
  54. ;*******************************************************************************
  55. CODESEG
  56. _allmul PROC NEAR
  57. A EQU [esp + 4] ; stack address of a
  58. B EQU [esp + 12] ; stack address of b
  59. ;
  60. ; AHI, BHI : upper 32 bits of A and B
  61. ; ALO, BLO : lower 32 bits of A and B
  62. ;
  63. ; ALO * BLO
  64. ; ALO * BHI
  65. ; + BLO * AHI
  66. ; ---------------------
  67. ;
  68. mov eax,HIWORD(A)
  69. mov ecx,HIWORD(B)
  70. or ecx,eax ;test for both hiwords zero.
  71. mov ecx,LOWORD(B)
  72. jnz short hard ;both are zero, just mult ALO and BLO
  73. mov eax,LOWORD(A)
  74. mul ecx
  75. ret 16 ; callee restores the stack
  76. hard:
  77. push ebx
  78. ; must redefine A and B since esp has been altered
  79. A2 EQU [esp + 8] ; stack address of a
  80. B2 EQU [esp + 16] ; stack address of b
  81. mul ecx ;eax has AHI, ecx has BLO, so AHI * BLO
  82. mov ebx,eax ;save result
  83. mov eax,LOWORD(A2)
  84. mul dword ptr HIWORD(B2) ;ALO * BHI
  85. add ebx,eax ;ebx = ((ALO * BHI) + (AHI * BLO))
  86. mov eax,LOWORD(A2) ;ecx = BLO
  87. mul ecx ;so edx:eax = ALO*BLO
  88. add edx,ebx ;now edx has all the LO*HI stuff
  89. pop ebx
  90. ret 16 ; callee restores the stack
  91. _allmul ENDP
  92. end