flat assembler
Message board for the users of flat assembler.
 flat assembler > Main > Integer limit in fasm1
Author
l4m2

Joined: 15 Jan 2015
Posts: 608

# 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 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?
05 Jan 2017, 18:10
Tomasz Grysztar
Assembly Artist

Joined: 16 Jun 2003
Posts: 6722
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.
05 Jan 2017, 18:18
l_inc

Joined: 23 Oct 2009
Posts: 881
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
06 Jan 2017, 01:11
l4m2

Joined: 15 Jan 2015
Posts: 608
 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
06 Jan 2017, 02:25
l4m2

Joined: 15 Jan 2015
Posts: 608
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 t-(x)/10) mod 10 + (1-(x)/10) mod 10 \\\{         match =- u, t \\\\{           f (x)/10         \\\\}       \\\}       rept 1 tx) 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)
06 Jan 2017, 03:07
Tomasz Grysztar
Assembly Artist

Joined: 16 Jun 2003
Posts: 6722
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).
06 Jan 2017, 08:44
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------Blog General----------------MainDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsCompiler InternalsIDE DevelopmentOS ConstructionNon-x86 architecturesHigh Level LanguagesProgramming Language DesignProjects and IdeasExamples and Tutorials 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