2 ;llmul.asm - long multiply routine
4 ; Copyright (c) Microsoft Corporation. All rights reserved.
5 ; SPDX-License-Identifier: BSD-2-Clause-Patent
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:
14 ;Original Implemenation: MSVC 14.12.25827
16 ;*******************************************************************************
23 ;llmul - long multiply routine
26 ; Does a long multiply (same for signed/unsigned)
27 ; Parameters are not changed.
30 ; Parameters are passed on the stack:
31 ; 1st pushed: multiplier (QWORD)
32 ; 2nd pushed: multiplicand (QWORD)
35 ; EDX:EAX - product of multiplier and multiplicand
36 ; NOTE: parameters are removed from the stack
43 ;*******************************************************************************
46 A EQU [esp + 4] ; stack address of a
47 B EQU [esp + 12] ; stack address of b
53 ; AHI, BHI : upper 32 bits of A and B
54 ; ALO, BLO : lower 32 bits of A and B
59 ; ---------------------
64 or ecx,eax ;test for both high dwords zero.
66 jnz short hard ;both are zero, just mult ALO and BLO
71 ret 16 ; callee restores the stack
76 ; must redefine A and B since esp has been altered
78 A2 EQU [esp + 8] ; stack address of a
79 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
85 mul dword ptr HIGH_PART(B2) ;ALO * BHI
86 add ebx,eax ;ebx = ((ALO * BHI) + (AHI * BLO))
88 mov eax,LOW_PART(A2);ecx = BLO
89 mul ecx ;so edx:eax = ALO*BLO
90 add edx,ebx ;now edx has all the LO*HI stuff
94 ret 16 ; callee restores the stack