flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Main > Integer limit in fasm1

Author
Thread Post new topic Reply to topic
l4m2



Joined: 15 Jan 2015
Posts: 588
Integer limit in fasm1
It's okay to write

Code:
x = $ffff'ffff'ffff'ffff(64b unsigned/65b signed)

but not

Code:
rept 1 x:$7fff'ffff {}(32b signedMAX 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
Assembly Artist


Joined: 16 Jun 2003
Posts: 6509
Location: Kraków, Poland
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: 875
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: 588

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: 588
So converting from number to int can't use a simple rept but

Code:
match, {
  local fsg
  rept 80 \{
    local tu
    macro f x \\{
      rept 1 tSad-(x)/10mod 10 + (1-(x)/10mod 10 \\\{
        match =- ut \\\\{
          f (x)/10
        \\\\}
      \\\}
      rept 1 tSadxmod 10 \\\{
        match gs \\\\{
          s equ g \\\\# t
        \\\\}
      \\\}
    \\}
  \}
  macro numy outin \{
    s equ /
    g equ in
    rept (1 - ((g))mod 2 - (1+(g))mod 2)/2 \\{
      s equ /-
      g equ -(in)
    \\}
    f g
    match /gs \\{
      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
Assembly Artist


Joined: 16 Jun 2003
Posts: 6509
Location: Kraków, Poland
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.