flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > REPT with multiple counters

Author
Thread Post new topic Reply to topic
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
While spelunking fasm source, I stumble upon interesting piece of code, which is related to parsing of rept directive parameters. In short, there may be several counter symbols (with corresponding optional starting values) specified, using comma as separator.
Code:
rept 3 x:10, y:20 { display `x, "+10=", `y, 13, 10 }

; Display:
; 10+10=20
; 11+10=21
; 12+10=22    
This feature was available from the beginning (1.62 for rept), though it usefulness is questionable (especially after 1.70, when rept become able to evaluate expressions).
Post 04 Apr 2013, 00:34
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
baldr
This is a nice one. It's probably more obvious, but the counters also support string initializers. Unfortunately, not even the complete 32 bit range is supported (I'd prefer consistent 65 bit arithmetic for the preprocessor as well).

In such cases I'm always interested in the author's comments, whether the behaviour is desired and whether it can be relied on in macros under consideration of future fasm releases.

_________________
Faith is a superposition of knowledge and fallacy
Post 05 Apr 2013, 22:50
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7734
Location: Kraków, Poland
Tomasz Grysztar
Right now the main purpose of this feature is to allow computing multiple expressions with a single REPT.

As for the counter range - in fasm every kind of repetition count, whether it is argument to REPT, REPEAT, TIMES, or value of % or REPT counter, is a 32-bit signed value.
Post 05 Apr 2013, 23:35
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
Tomasz Grysztar
OK. Thank you for the clarification.

_________________
Faith is a superposition of knowledge and fallacy
Post 06 Apr 2013, 00:01
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
Tomasz Grysztar
It seems I didn't verify the statement regarding 32-bit signed type of arguments for repeat and times last time. How does the following code comply with it?
Code:
repeat 0xFFFFFFFF
    if % > 1
        break
    end if
    display 'Hello',13,10
end repeat    

The result clearly differs to that after changing the argument to -1.

_________________
Faith is a superposition of knowledge and fallacy
Post 17 Mar 2015, 14:34
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7734
Location: Kraków, Poland
Tomasz Grysztar
My mistake, it probably should be an "unsigned" there. I checked the "get_count_value" routine that is used for counts like REPEAT/TIMES arguments, and it certainly gives back a 32-bit unsigned number (it throws an "invalid value" error if the expression gave a negative result). The REPT directive is thus overzealous in its argument checking, I probably wrote that check under the impression that "get_count_value" returns signed value (not that it is a real problem, since REPT with such high count would run out of memory anyway).
Post 17 Mar 2015, 14:46
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
Tomasz Grysztar
As for the rept it's rather relevant if larger initialization values are allowed, cause that defines the limits of preprocessor driven calculations. The repeat and times directives do not allow to specify the initial value of the counter anyway.

_________________
Faith is a superposition of knowledge and fallacy
Post 17 Mar 2015, 15:31
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7734
Location: Kraków, Poland
Tomasz Grysztar
l_inc wrote:
Tomasz Grysztar
As for the rept it's rather relevant if larger initialization values are allowed, cause that defines the limits of preprocessor driven calculations. The repeat and times directives do not allow to specify the initial value of the counter anyway.
This would require additional check to make sure that initial value of counter plus the number of repetitions would not overflow. With current restriction such check was not necessary (because adding two positive values from signed range cannot overflow in the unsigned range) so it's not there. Actually I might have done it on purpose.
Post 17 Mar 2015, 15:56
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
Tomasz Grysztar
I'm not sure, what you refer to. If it's rept, then the check seems to be there:
Code:
rept 1 i:$7FFFFFFF { display 'Hello',13,10 }    

As for the repeat it uses the unsigned range and the initial value specification is rather irrelevant.

_________________
Faith is a superposition of knowledge and fallacy
Post 17 Mar 2015, 16:38
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7734
Location: Kraków, Poland
Tomasz Grysztar
Right, there is a check that guards the signed range again, and in general the signed range is assumed everywhere in context of preprocessor. In short: the range for preprocessor's counters is 32-bit signed, while for assembler's counters is 32-bit unsigned.
Post 17 Mar 2015, 17:12
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
Tomasz Grysztar
Now that we know, that the preprocessor's counters are handled differently, what was the problem again to let the preprocessor support 65-bit calculations? Smile I mean that would add uniformity.

_________________
Faith is a superposition of knowledge and fallacy
Post 17 Mar 2015, 17:23
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7734
Location: Kraków, Poland
Tomasz Grysztar
l_inc wrote:
Tomasz Grysztar
Now that we know, that the preprocessor's counters are handled differently, what was the problem again to let the preprocessor support 65-bit calculations? Smile I mean that would add uniformity.
The preprocessor uses the same expression calculator that is used by the assembler, so it supports the 65-bit values during the calculations. Only when the result of calculation has to be used, it needs to fit the restricted range - just like in the case of assembler's REPEAT, which also accepts only the result of calculation that fits the required range. It's just that the range is a bit different.

The range needed to be 32-bit anyway, because changing it to something larger would require more substantial rewrite of macro handling code. I think I chose the signed over the unsigned range for counter bases because REPT directive was intended to provide some expression evaluation abilities to preprocessor, and signed range meant allowing evaluation of negative values.
Post 17 Mar 2015, 19:45
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
Tomasz Grysztar
Quote:
changing it to something larger would require more substantial rewrite of macro handling code

Thanks again for the clarification. I'm taking it as is, though I can think of an explanation only in terms of a counter-evidence to [url=nowhere]this[/url] .

P.S. Sorry, didn't initially notice it was a nowhere link. I guess you still can see the original version of the post.

_________________
Faith is a superposition of knowledge and fallacy
Post 17 Mar 2015, 22:55
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. Also on YouTube, Twitter.

Website powered by rwasa.