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