From da83c3cc9c1f5431b0160550715bae7bd980cf26 Mon Sep 17 00:00:00 2001 From: OlimilO1402 Date: Wed, 2 Mar 2022 18:36:05 +0100 Subject: [PATCH] finally calculation of UInt64_Mul is correct --- Forms/Form1.frm | 19 +++++++++---------- UnsignedOpsDll/UnsignedOps.asm | 12 +++++++----- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Forms/Form1.frm b/Forms/Form1.frm index d5dbe0d..7d3adf3 100644 --- a/Forms/Form1.frm +++ b/Forms/Form1.frm @@ -353,17 +353,16 @@ Sub TestDll() d = UInt64_Mul(c1, c2) Debug_Print VarType(d) & " " & CStr(d) '14 121932631112635269 - - '628239210217683 - '41419963890366 - - c1 = 214748.3647 '1234.5678 '62823921021.7683 - c2 = 214748.3647 '4141996389.0366 - '2147483647*2147483647=4611686014132420609 - + + ' 2147483647 * 2147483647 = 4611686014132420609 + 'c1 = 214748.3647 + 'c2 = 214748.3647 + + '628239210217683 * 41419963890366 = 26021645401728484450406541978 + c1 = 62823921021.7683 + c2 = 4141996389.0366 d = UInt64_Mul(c1, c2) - Debug_Print VarType(d) & " " & CStr(d) '14 26021645401728484450406541978 - ' + Debug_Print VarType(d) & " " & CStr(d) s = Space(20): UInt64_ToHex cret, StrPtr(s) Debug_Print Trim0(s) diff --git a/UnsignedOpsDll/UnsignedOps.asm b/UnsignedOpsDll/UnsignedOps.asm index b858bb2..b1d0d6a 100644 --- a/UnsignedOpsDll/UnsignedOps.asm +++ b/UnsignedOpsDll/UnsignedOps.asm @@ -351,9 +351,9 @@ UInt64_Sub endp ; ByVal V1 As Currency, ByVal V2 As Currency, ByVal pDec_out As LongPtr UInt64_Mul proc - ;int 3 - - ; 1. prepare Variant as type Decimal + ;int 3 + + ; 1. prepare Variant as type Decimal mov edi , [esp+20] ; copy the pointer to a Variant from stack to register EDI mov dx , 14 ; copy the vartype-word for decimal it is 14 = &HE to the register dx mov [edi+ 0], dx ; copy the value in register dx to the Variant to the first int16-slot @@ -389,8 +389,10 @@ UInt64_Mul proc pushfd ; Save carry out here. ; 5. Multiply the two Hi dwords together, - mov eax , [esp+ 8] ; Get Hi dword of Multiplier - mul dword ptr [esp+16] ; Multiply by Hi dword of Multiplicand + ;mov eax , [esp+ 8] ; Get Hi dword of Multiplier + mov eax , [esp+12] + ;mul dword ptr [esp+16] ; Multiply by Hi dword of Multiplicand + mul dword ptr [esp+20] popfd ; Retrieve carry from above adc eax , ecx ; Add in partial product from above. adc edx , 0 ; Don't forget the carry!