flat assembler
Message board for the users of flat assembler.

 Index > Compiler Internals > 64 bit calculation / 65 bit storage
Author
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 18027
revolution
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?
25 Jul 2005, 02:20
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 18027
revolution
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.
30 Apr 2009, 03:39
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 18027
revolution
Things might be changing so the above behaviour might soon no longer be true.
28 Feb 2012, 00:48
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum