flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Interesting idea for macro repetition

Goto page Previous  1, 2, 3  Next
Author
Thread Post new topic Reply to topic
Ancient One



Joined: 28 Feb 2005
Posts: 55
Ancient One
i suggest we use breed like this :
Code:
breed [j, i name] line
    


which means :
repeat line j times, starting the counter from i; name represents the counter count (any occurence of name in line will be replaced by the current count number). i or/and name can always be omitted so we can always write the simple breed [j] line which means repeat line j times, or breed[j counter] line. if i is not specified, its value defaulted to 1 (or 0?). only j should always be specified here (even if it's 0).

example :
Code:
breed [0] include "debug.mac"
;repeat line include "debug.mac" 0 times.
;j=0, i is assumed to be 0, no counter name.
    


Code:
macro foo x {
    display `x,13,10
}

breed [3, 10 %c] foo %c
;foo 10
;foo 11
;foo 12

;iterative use of breed

breed [5 %c1] breed [%c1 %c] foo %c

;firstly :
;breed [1 %c] foo %c
;breed [2 %c] foo %c
;breed [3 %c] foo %c
;breed [4 %c] foo %c
;breed [5 %c] foo %c

;then :
;foo 1
;foo 1
;foo 2
;foo 1
;foo 2
;foo 3
;foo 1
;foo 2
;foo 3
;foo 4
;foo 1
;foo 2
;foo 3
;foo 4
;foo 5
    


and maybe we can make the pp to accepts negative value of "j" so we can count backwards. e.g
Code:
breed [-3,3 %c] foo %c
;foo 3
;foo 2
;foo 1
    

we can set the min/max (internal) value to certain value, so the increment/decrement stop when reaching this limit. e.g, if we set i to default at 1 and minimum value of i is also 1. then
Code:
breed [-3 %c] foo %c
    

will become
Code:
foo 1
foo 1
foo 1
    
Post 05 Mar 2005, 06:43
View user's profile Send private message MSN Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
Good idea, though I think I would still prefer something like:
Code:
breed [name,i] j line    

with the brackets-surrounded parameters being optional (i - first value, j - count of duplicates). Possible extended form:
Code:
breed [name,i,step] j line    

where step would be the value added to i after each duplicate.
Post 13 Mar 2005, 12:16
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
looks good
Post 13 Mar 2005, 22:54
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
MCD
looks good so far, but please, I really don't like the worg breed...
Post 14 Mar 2005, 19:10
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
Do you prefer "dupe"? For some reason do not. Wink Very Happy

But seriously: "clone" is also a good alternative. Its meaning is quite similar in this context.
I preferred "breed", because it sounds almost like an English phrase: "breed 5 instructions", etc.
Post 14 Mar 2005, 20:14
View user's profile Send private message Visit poster's website Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
MCD
okay, this is only a question of taste. I think someone should start a poll on this.
Post 15 Mar 2005, 08:10
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17719
Location: In your JS exploiting you and your system
revolution
Yes, the "breed" looks like a good idea.

But how about something similar to the way the assembler uses "repeat". Like this:

Code:
breed 20
call @f
dd %
@@:
end breed
    


And the normal arithmetic should allow using "(%-1)*4" type of coding to generate whatever range of values is needed.

Regarding the name: Hmm, somehow breed does not seem appropriate. Basically it is a preprocessor type of repeat so how about "prepeat" or "pre-repeat" or "multiple-generate" or "mgen". I don't think that trying to find a suitable English word is necessary.

Of course, the names suggested above are a little quirky, don't take them too seriously. But, instead is it possible to move "repeat" into the preprocessor stage? The % can still be replaced as usual and I think the code generated would not change but it would allow constructions just like I show above to work intuitively.
Post 18 Mar 2005, 06:23
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
revolution wrote:
But, instead is it possible to move "repeat" into the preprocessor stage? The % can still be replaced as usual and I think the code generated would not change but it would allow constructions just like I show above to work intuitively.

No, it wouldn't be the same. Consider just:
Code:
repeat 1000-$
 db %
end repeat
    


And "breed" is rather a preprocessor's "times" directive than preprocessor's "repeat". And since you can use macro inside a line, which you duplicate, there is no need to implement any "repeat" equivalent.
Post 18 Mar 2005, 06:30
View user's profile Send private message Visit poster's website Reply with quote
Ancient One



Joined: 28 Feb 2005
Posts: 55
Ancient One
Privalov wrote:
Good idea, though I think I would still prefer something like:
Code:
breed [name,i] j line    

with the brackets-surrounded parameters being optional (i - first value, j - count of duplicates). Possible extended form:
Code:
breed [name,i,step] j line    

where step would be the value added to i after each duplicate.


yeah, it looks good to me.

i think the word 'breed' is a good name for this directive.
Post 19 Mar 2005, 07:51
View user's profile Send private message MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
breed is allright
Post 21 Mar 2005, 14:05
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
Another new idea is to make something more similar to macro syntax, like:
Code:
prerep 15 
{
  ; source that will be repeated 15 times
}

prerep 15 counter
{
  ; in this source "counter" will be replaced with number of repetition
}    

and also:
Code:
preif symbol eq other_symbol
{
  ; conditionally preprocessed code
}    


The only problem it has that "breeed" has not is that using it within marcos would require fixing some symbols for the braces again (as with standard macros within macros).
Post 10 May 2005, 11:30
View user's profile Send private message Visit poster's website Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM
I think 'breed' is ok.

_________________
This calls for... Ultra CRUNCHY Man!
Ta da!! *crunch*
Post 10 May 2005, 21:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17719
Location: In your JS exploiting you and your system
revolution
Privalov. I think your suggestion of using the braces is much better than the single line approach mentioned for breed.
Post 11 May 2005, 01:06
View user's profile Send private message Visit poster's website Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
MCD
revolution wrote:
Privalov. I think your suggestion of using the braces is much better than the single line approach mentioned for breed.

I can only agree with you, especially because preprocessor in fasm is not (completely) line based, but also block based. (stuff like macors, structures etc...)

_________________
MCD - the inevitable return of the Mad Computer Doggy

-||__/
.|+-~
.|| ||
Post 11 May 2005, 09:36
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
yes, i don't like declaring new macro for each repeated block.

about the problem: couldn't you add something like i mentioned you before - some symbol, let's say "@", which will be normal part of name like ".", but every symbol starting with "@" will have it removed when unrolling macro.

Something like
Code:
macro declare_macro_XXX
{ 
   macro XXX
   @{
      asdas
   @}
}
declare_macro_XXX
    

So "@" thingy will be kind of equivalent for fixes, but much easier to use, more readable, more comprehendable, will allow macros independent from particular fixes etc.

i quess you would have to rewrite prepreprocessor a little not to separate @ and { symbol, please think if it could be done.
Post 11 May 2005, 09:46
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
I think about something like:
Code:
macro first
{
   macro second
   {
      macro third
      {
          
      \\}
   \}
}    

The backlash character is already treated specially by line splitter, so this wouldn't complicate anything. And there shouldn't be confusion with line concatenation operator, since only comments after it are allowed.
Post 11 May 2005, 10:38
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Hm, I wonder, isn't it possible to make clear recurcive macro behaviour. I mean:

Code:
macro first
{
   macro second
   {
      macro third
      {
          
      }
   }
}    


This will need only a counter that to be incremented on every "{" and decremented on every "}", so, if after decrement, the counter is 0, then the "}" character should be treated as an end of macro definition, else should be treated as a simple character.

Regards
Post 11 May 2005, 11:04
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
But what when you want to begin macro definition with one macro and end with another (like the current "struct" macro does)?
Post 11 May 2005, 11:17
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
Implementing such backslashes feature is quite simple - I'm attaching the modified preprocessor module that has it.

Attachment removed - now it's implemented in official releases


Last edited by Tomasz Grysztar on 19 May 2005, 12:16; edited 1 time in total
Post 11 May 2005, 11:26
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Privalov wrote:
But what when you want to begin macro definition with one macro and end with another (like the current "struct" macro does)?


Well, "fix" is still here. Smile
Post 11 May 2005, 11:30
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3  Next

< 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 GitHub, YouTube, Twitter.

Website powered by rwasa.