Skip to content

Commit

Permalink
finally calculation of UInt64_Mul is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
OlimilO1402 committed Mar 2, 2022
1 parent 869d07e commit da83c3c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
19 changes: 9 additions & 10 deletions Forms/Form1.frm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions UnsignedOpsDll/UnsignedOps.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down

0 comments on commit da83c3c

Please sign in to comment.