From: fly on
Hello,
i'm trying to mutiply two numbers useing Asemlber:
4 294 967 295 and 4 294 967 295 ;)
the code:
....
mianownik1 dq 0
mianownik2 dq 0
..
..
mov dword ptr mianownik1,esi
mov dword ptr mianownik2,esi
..
..
fild mianownik1
fild mianownik2
fmulp

The answer i get is wrong. there should be 18446744065119617025
and I get 18446744065119617020.
I view the aswer by OllyDbg in the FPU registers. Everything seems to be
ok, but the multiplying is wrong. Any ideas why that's happening?


Thanks in advance

fly

From: spamtrap on

fly wrote:
> Hello,
> i'm trying to mutiply two numbers useing Asemlber:
> 4 294 967 295 and 4 294 967 295 ;)
> the code:
> ...
> mianownik1 dq 0
> mianownik2 dq 0

Here you define 2 quadwords...

> .
> .
> mov dword ptr mianownik1,esi
> mov dword ptr mianownik2,esi

I don't know what this is for...

> .
> .
> fild mianownik1

Here there is no mention that 'mianownik1' is a pointer to a
quadword...

> fild mianownik2

ditto...

> fmulp
>

Nathan.

From: Evenbit on

fly wrote:
> Hello,
> i'm trying to mutiply two numbers useing Asemlber:
> 4 294 967 295 and 4 294 967 295 ;)
> the code:
> ...
> mianownik1 dq 0
> mianownik2 dq 0

Here, you define 2 quadwords...

> .
> .
> mov dword ptr mianownik1,esi
> mov dword ptr mianownik2,esi

I don't know what this is for...

> .
> .
> fild mianownik1

Here, you forget to tell the assembler that 'mianownik1' is a pointer
to a quadword...

> fild mianownik2

ditto...

> fmulp
>
> The answer i get is wrong. there should be 18446744065119617025
> and I get 18446744065119617020.
> I view the aswer by OllyDbg in the FPU registers. Everything seems to be
> ok, but the multiplying is wrong. Any ideas why that's happening?
>
>
> Thanks in advance
>
> fly

Nathan.

From: randyhyde@earthlink.net on

fly wrote:
> Hello,
> i'm trying to mutiply two numbers useing Asemlber:
> 4 294 967 295 and 4 294 967 295 ;)
> the code:
> ...
> mianownik1 dq 0
> mianownik2 dq 0
> .
> .
> mov dword ptr mianownik1,esi
> mov dword ptr mianownik2,esi
> .
> .
> fild mianownik1
> fild mianownik2
> fmulp
>
> The answer i get is wrong. there should be 18446744065119617025
> and I get 18446744065119617020.
> I view the aswer by OllyDbg in the FPU registers. Everything seems to be
> ok, but the multiplying is wrong. Any ideas why that's happening?
>
>

Well, for one thing you're getting overflow.
The product of $ffff_ffff and $FFFF_FFFF requires 64 bits to hold. But
the 80-bit floating point value holds a 64-bit *signed* value.
Therefore, you start to lose precision (that is, the FPU approximates
the value) when you multiply numbers whose signed result cannot fit in
64 bits (including the sign bit).
Cheers,
Randy Hyde

From: o//annabee on
P? Mon, 03 Apr 2006 17:46:58 +0200, skrev fly <spamtrap(a)crayne.org>:

> Hello,
> i'm trying to mutiply two numbers useing Asemlber:
> 4 294 967 295 and 4 294 967 295 ;)
> the code:
> ...
> mianownik1 dq 0
> mianownik2 dq 0
> .
> .
> mov dword ptr mianownik1,esi
> mov dword ptr mianownik2,esi
> .
> .
> fild mianownik1
> fild mianownik2
> fmulp
>
> The answer i get is wrong. there should be 18446744065119617025
> and I get 18446744065119617020.

What you do is load -1 twice to the FPU. The result should be 1.

To load what you really want, use a 64 bit variable.

> I view the aswer by OllyDbg in the FPU registers. Everything seems to be
> ok, but the multiplying is wrong. Any ideas why that's happening?
>
>
> Thanks in advance
>
> fly
>