flat assembler
Message board for the users of flat assembler.

Index > Main > Integer limit in fasm1

Author
Thread Post new topic Reply to topic
l4m2



Joined: 15 Jan 2015
Posts: 670
l4m2 05 Jan 2017, 18:10
It's okay to write
Code:
x = $ffff'ffff'ffff'ffff(64b unsigned/65b signed)    
but not
Code:
rept 1 x:$7fff'ffff {}(32b signed, MAX not avaliable)    
Why it differs? So you can write
Code:
x equ $ffff'ffff'ffff    
but can it be possible to compare x with some other integer?
Post 05 Jan 2017, 18:10
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8434
Location: Kraków, Poland
Tomasz Grysztar 05 Jan 2017, 18:18
Yes, fasm's preprocessor is limited to 32-bit signed numbers. Keep in mind that fasm's preprocessor is a separate language on top of the assembler.
Post 05 Jan 2017, 18:18
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc 06 Jan 2017, 01:11
Well, that is not the whole truth. I didn't do a thorough investigation, but it seems the preprocessor can work with wider integers as long as these are intermediate values. As we are talking about comparison here, the following code correctly finds the maximum value of $ffff'ffff'ffff and $1'0000'0000'0000 (equmax from here):
Code:
x equ $ffff'ffff'ffff
y equ $1'0000'0000'0000

m equmax x,y
match v,m { display `v,13,10 }    


That works as long as the computed difference fits into the 32-bit signed range. If not (like if one of the above values was 1 instead), a more generalized version would be needed:
Code:
struc equmax v1*,v2*
{
    restore .
    . equ v1
    rept 1 diff_hi : (v1)shr 30 - (v2)shr 30
    \{
        match =0,diff_hi
        \\{
            rept 1 diff_lo : (v1)and $3fffffff - (v2)and $3fffffff
            \\\{
                match - any,diff_lo
                \\\\{
                    rept 0 \\\\\{
        \\}
        match,
        \\{
            match - any,diff_hi
            \\\{
                match, \\\\{\\\\}
                restore .
                . equ v2
            \\\}
        \\}
    \}
}    

The above macro allows to compare 60-bit values. Any other calculations could be extended this way.

_________________
Faith is a superposition of knowledge and fallacy
Post 06 Jan 2017, 01:11
View user's profile Send private message Reply with quote
l4m2



Joined: 15 Jan 2015
Posts: 670
l4m2 06 Jan 2017, 02:25
l_inc wrote:

Tested.
Code:
x equ $ffff'ffff'ffff
rept 1 t:x shr 40 {}    
complied, which means that prepro. allows large value but not as a loop counter
Post 06 Jan 2017, 02:25
View user's profile Send private message Reply with quote
l4m2



Joined: 15 Jan 2015
Posts: 670
l4m2 06 Jan 2017, 03:07
So converting from number to int can't use a simple rept but
Code:
match, {
  local f, s, g
  rept 80 \{
    local t, u
    macro f x \\{
      rept 1 tSad-(x)/10) mod 10 + (1-(x)/10) mod 10 \\\{
        match =- u, t \\\\{
          f (x)/10
        \\\\}
      \\\}
      rept 1 tSadx) mod 10 \\\{
        match g, s \\\\{
          s equ g \\\\# t
        \\\\}
      \\\}
    \\}
  \}
  macro numy out, in \{
    s equ /
    g equ in
    rept (1 - ((g))mod 2 - (1+(g))mod 2)/2 \\{
      s equ /-
      g equ -(in)
    \\}
    f g
    match /g, s \\{
      out equ g
    \\}
  \}
}
numy out, $146841654
out    
?(This code may not work if the value is near MAX or MIN)
Post 06 Jan 2017, 03:07
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8434
Location: Kraków, Poland
Tomasz Grysztar 06 Jan 2017, 08:44
REPT uses the same expression evaluator as the assembler module, so during the expression evaluation the same rules and limits apply (note that the results of expressions are mostly well defined for any value sizes, only the limitations of implementation cause errors - compare with fasmg implementation of the same evaluator). However where the preprocessor itself operates on numbers, it is limited to 32-bit values, since it was designed this way (the addition of REPT with its use of the assembler's calculator was a late one).
Post 06 Jan 2017, 08:44
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.