flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > 64 bit calculation / 65 bit storage

Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20303
Location: In your JS exploiting you and your system
revolution 25 Jul 2005, 02:20
Having recently been using the assembler for 64 bit calculations (see RSA) I came across a problem that reminded me of the TASM 33 bit values.

Of course TASM is a 32 bit assembler but it always kept values to a precision of 33 bits internally. The reason for this was the sign of the result. Example:

In TASM (32 bit assembler)

(0FFFFh * 0FFFFH)/0FFFFh = 0FFFFh

Internally (0FFFFh * 0FFFFH) = 0FFFE0001h with sign positive and the the division by 0FFFFh gives the expected answer.

In FASM (64 bit assembler):

(0FFFFFFFFh * 0FFFFFFFFh)/0FFFFFFFFh = 0FFFFFFFFFFFFFFFEh

Whoops, what happened? Internally (0FFFFFFFFh * 0FFFFFFFFh) = 0FFFFFFFE00000001h, a negative number. Fasm reports no error when we multiply two positive numbers and get a negative result. Indeed FASM continues on with the divide and makes the result negative to match the sign or the numerator.

To avoid unexpected results perhaps we can have one extra bit that stores the sign of the result for arithmetic calculations? Is this possible to do in FASM without major modifications? Perhaps instead, if adding and extra sign bit is not easily done, FASM can report an overflow error when a multiplication produces and unexpected sign change?
Post 25 Jul 2005, 02:20
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20303
Location: In your JS exploiting you and your system
revolution 30 Apr 2009, 03:39
Just thought I should point out that shortly after the message above was written the internal fasm number handling was changed. The new behaviour is that currently fasm does generate an error if two positive numbers are multiplied together and a negative result is encountered.
Post 30 Apr 2009, 03:39
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20303
Location: In your JS exploiting you and your system
revolution 28 Feb 2012, 00:48
Things might be changing so the above behaviour might soon no longer be true.
Post 28 Feb 2012, 00:48
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.