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.

98 lines
2.4 KiB

  1. title llmul - long multiply routine
  2. ;***
  3. ;llmul.asm - long multiply routine
  4. ;
  5. ; Copyright (c) 1985-1994, 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. .xlist
  16. include cruntime.inc
  17. include mm.inc
  18. .list
  19. ;***
  20. ;llmul - long multiply routine
  21. ;
  22. ;Purpose:
  23. ; Does a long multiply (same for signed/unsigned)
  24. ; Parameters are not changed.
  25. ;
  26. ;Entry:
  27. ; Parameters are passed on the stack:
  28. ; 1st pushed: multiplier (QWORD)
  29. ; 2nd pushed: multiplicand (QWORD)
  30. ;
  31. ;Exit:
  32. ; EDX:EAX - product of multiplier and multiplicand
  33. ; NOTE: parameters are removed from the stack
  34. ;
  35. ;Uses:
  36. ; ECX
  37. ;
  38. ;Exceptions:
  39. ;
  40. ;*******************************************************************************
  41. CODESEG
  42. _allmul PROC NEAR
  43. A EQU [esp + 4] ; stack address of a
  44. B EQU [esp + 12] ; stack address of b
  45. ;
  46. ; AHI, BHI : upper 32 bits of A and B
  47. ; ALO, BLO : lower 32 bits of A and B
  48. ;
  49. ; ALO * BLO
  50. ; ALO * BHI
  51. ; + BLO * AHI
  52. ; ---------------------
  53. ;
  54. mov eax,HIWORD(A)
  55. mov ecx,HIWORD(B)
  56. or ecx,eax ;test for both hiwords zero.
  57. mov ecx,LOWORD(B)
  58. jnz short hard ;both are zero, just mult ALO and BLO
  59. mov eax,LOWORD(A)
  60. mul ecx
  61. ret 16 ; callee restores the stack
  62. hard:
  63. push ebx
  64. ; must redefine A and B since esp has been altered
  65. A2 EQU [esp + 8] ; stack address of a
  66. B2 EQU [esp + 16] ; stack address of b
  67. mul ecx ;eax has AHI, ecx has BLO, so AHI * BLO
  68. mov ebx,eax ;save result
  69. mov eax,LOWORD(A2)
  70. mul dword ptr HIWORD(B2) ;ALO * BHI
  71. add ebx,eax ;ebx = ((ALO * BHI) + (AHI * BLO))
  72. mov eax,LOWORD(A2) ;ecx = BLO
  73. mul ecx ;so edx:eax = ALO*BLO
  74. add edx,ebx ;now edx has all the LO*HI stuff
  75. pop ebx
  76. ret 16 ; callee restores the stack
  77. _allmul ENDP
  78. end