flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > mixed multiple optional macro arguments

Author
Thread Post new topic Reply to topic
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
suppose you have:
Code:
macro foo title,[name,value] {
    i = 0
    forward
        i = i + 1
        display "foo ",i+30h,":",13,10
        display 9,"name:",9,name,13,10
        display 9,"value:",9,value,13,10
    common
        bar name,value
}
macro bar [name,value] {
    i = 0
    forward
        i = i + 1
        display "bar ",i+30h,":",13,10
        display 9,"name:",9,name,13,10
        display 9,"value:",9,value,13,10
}

foo "title","include","yes","name","value","one","1","two","2"
    


the results will be displayed correctly from foo, but when passed to bar, it will mix name and value together, resulting in sequence of all names first, then values, as opposed to pairs of name and value.

Code:
foo 1:
        name:       include
     value:      yes
foo 2:
   name:       name
        value:      value
foo 3:
 name:       one
 value:      1
foo 4:
     name:       two
 value:      2
bar 1:
     name:       include
     value:      name
bar 2:
  name:       one
 value:      two
bar 3:
   name:       yes
 value:      value
bar 4:
 name:       1
   value:      2    


foo is correct, and bar is not. What to do? How to fix?

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 20 Feb 2004, 18:09
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 875
Location: Colombia
pelaillo
Code:
macro foo title,[name,value] {
    i = 0
    forward
        i = i + 1
        display "foo ",i+30h
        display 9,"name:",9,name,13,10
        display 9,9,"value:",9,value,13,10
    common
        display name,13,10
        bar name,value
}

macro bar [name,value] {
  common
    bar2 name,value
}

macro bar1 [name,value] {
    i = 0
    forward
        i = i + 1
        display "bar ",i+30h
        display 9,"name:",9,name,13,10
        display 9,9,"value:",9,value,13,10
}

macro bar2 [name,value] {
    common
    bar1 name,value
}
    
Post 20 Feb 2004, 19:15
View user's profile Send private message Yahoo Messenger Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
Heh, nice Smile Fixing the bug by using the bug Smile
Muchos gracias Smile

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 20 Feb 2004, 21:38
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
Hmm, the amount of passing you have to do depends on number of name/value pairs. Trying to make recursive passage leads to "illegal instruction error". It look like FASM does not allow make recursive macro call. Even if you have two macros, one calling each other, it will still have same error, because apparently macro cannot call its parent (theoretically that also result in recursive call).

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 20 Feb 2004, 21:49
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 875
Location: Colombia
pelaillo
Yes, I'm affraid Sad
I was triyng with counters and mod but nothing.
I think it remains only to fix the bug Smile
Post 20 Feb 2004, 23:23
View user's profile Send private message Yahoo Messenger Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
And so we wait for the master...

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 20 Feb 2004, 23:43
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
S.T.A.S.



Joined: 09 Jan 2004
Posts: 173
Location: Ru#27
S.T.A.S.
Code:
macro foo title,[name,value] {
    common i = 0
    local  boo
    forward
        i = i + 1
        display "foo ",i+30h,":",13,10
        display 9,"name:",9,name,13,10
        display 9,"value:",9,value,13,10
        boo fix   boo, name,value
    common
        bar boo
}

macro bar dummy,[name,value] {
    i = 0
    forward
        i = i + 1
        display "bar ",i+30h,":",13,10
        display 9,"name:",9,name,13,10
        display 9,"value:",9,value,13,10
}     


result
Code:
foo 1:
  name:       include
     value:      yes
foo 2:
   name:       name
        value:      value
foo 3:
 name:       one
 value:      1
foo 4:
     name:       two
 value:      2
bar 1:
     name:       include
     value:      yes
bar 2:
   name:       name
        value:      value
bar 3:
 name:       one
 value:      1
bar 4:
     name:       two
 value:      2    
Post 21 Feb 2004, 05:07
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7413
Location: Kraków, Poland
Tomasz Grysztar
From the fasm's manual:
Quote:
If some name inside macroinstruction has multiple values (it is either one of the arguments enclosed in square brackets or local name defined in the block following forward or reverse directive) and is used in block following the common directive, it will be replaced with all of its values, separated with commas.

So when "name" has multiple values of "include", "name", "one" and "two"; in common block "name" is replaced with "include,name,one,two". In the same way the "value" is replaced in common block with "yes,value,1,2". So when you write:
Code:
common 
bar name,value    

it becomes:
Code:
bar "include","name","one","two" , "yes","value","1","2"    
Post 21 Feb 2004, 09:53
View user's profile Send private message Visit poster's website Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
Ok, so how do I get desirable effect?

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 21 Feb 2004, 17:16
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7413
Location: Kraków, Poland
Tomasz Grysztar
Use "fix", as S.T.A.S, or just redesign your macros.
Post 21 Feb 2004, 21:24
View user's profile Send private message Visit poster's website Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
Don't you agree desireable effect is not to concatenate into one line? I do not understand why this "behaviour" is considered correct

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 21 Feb 2004, 22:53
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
Problem with fix is it is constant; I desire dynamic values

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 22 Feb 2004, 01:34
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
S.T.A.S.



Joined: 09 Jan 2004
Posts: 173
Location: Ru#27
S.T.A.S.
Quote:
not to concatenate into one line

It's not desirable *every* time.
For your current purpose it's better to be so, for other ones it could be better to keep things as they are.

IMHO, it's always better to have the choise.
And FASM gives us it. We can use current sintaxis or just FIX some thing Wink

BTW, I'm confused, why fix don't suit you?
It's not constant, "fix" just builds a list of foo's parameters avery time you call the macro, and then pass them to the next macro, just adding emty one at the beginning of the list.
So bar always get the same parameters as foo has.
Just one thing to be worked arround - the first "dummy" parameter, but it's not problem at all, I think.
I guess, your real macro are much more complex that this given example Wink
Post 22 Feb 2004, 07:07
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7413
Location: Kraków, Poland
Tomasz Grysztar
comrade wrote:
Don't you agree desireable effect is not to concatenate into one line? I do not understand why this "behaviour" is considered correct

What do you really mean? The current behavior logically comes from the idea of "forward"/"reverse"/"common" feature - with "common" block you have an arrays of parameters, as this block is processed for all the parameters at once. So the names of parameters are replaced with the entire arrays; the only other logical solution was to not allow to use such names in common blocks at all, but it would be only more limiting (though I often used such kind of design in fasm, just to avoid any logical inconsequencies).
Post 22 Feb 2004, 14:32
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-2019, Tomasz Grysztar.

Powered by rwasa.