flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > about division

Author
Thread Post new topic Reply to topic
daluca



Joined: 05 Nov 2005
Posts: 86
daluca
I know that constants or assembly-time variables are 64bit long
Code:

a=18446744073709551615

    


and when i perform a division Quad by Quad like:

Code:

a=18446744073709551615/18446744073709551615

if a=0
      display 'zero'
else 
      a=a+'0'
      display a
end if

    


I get the correct result: '1'
but for instance if I remove the digit 5 from the divisor
I get 'zero',but the correct result should be ':'=(10+'0')
does anyone know why is this?
Post 03 Mar 2007, 07:35
View user's profile Send private message Reply with quote
Goplat



Joined: 15 Sep 2006
Posts: 181
Goplat
fasm uses signed 64 bit numbers, so if you type 18446744073709551615 you actually get -1. Divide that by 1844674407370955161 and you get zero.
Post 03 Mar 2007, 22:28
View user's profile Send private message Reply with quote
daluca



Joined: 05 Nov 2005
Posts: 86
daluca
thanks Goplat I miss to think in that possibility.

I was making a macro to display values in decimal format and everything seemed to be right with 32bit numbers but wen I try to extend the macro to
64bit I get a "value out of range" error because I was considering the largest
number a 20 digits one, but is in fact 19 digits so I modify the macro and
seems to work ok:

Code:

macro disp number
{
        a=number
if a=0
        display '0'
else

        sign=(number) and 0x8000000000000000
        if sign<>0
           display '-'
           a = -a
        end if

        first0=0
        base= 1000000000000000000
             ;9223372036854775808
             repeat 19
                    digit=a/base
                    if digit=0
                       if first0=1
                          display '0'
                       end if
                    else
                       digit=digit+'0'
                       display digit
                       first0=1
                    end if

                    a=a mod base
                    base=base/10
              end repeat
end if
}


alfa= -1000
repeat 2000
disp alfa
display 13,10
alfa=alfa+1
end repeat
display '9223372036854775808 mod 45613211 = '
disp 9223372036854775808 mod 45613211

    


just copy,paste and compile and get the display.
it can be use to display some more complicated values like:

Code:

disp (alpha-(alpha/3)) mod 45

    
Post 04 Mar 2007, 07:17
View user's profile Send private message 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-2020, Tomasz Grysztar.

Powered by rwasa.