flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Using macros like variables?

Author
Thread Post new topic Reply to topic
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
How can I do something like this?

if (macroA blah,blahblah,pizza = 1) & (macroB foo,bar = 2)


Do I have a make a macro to replace "if" that somehow parses stuff like this, or is there already a facility in FASM that can do this? And if so, what do I put the return value in?

_________________
Post 24 Dec 2009, 06:47
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
You have to do it yourself and also you'll need to make your macros cooperate with this (like using a "RESULT" variable since macros don't have return value.

Make sure it really worths the effort, specially considering you could just write this instead:
Code:
macroA blah,blahblah,pizza
if RESULT = 1
  macroB foo, bar
  if RESULT = 2
   ...

; Or this if you need long-circuit

macroA blah,blahblah,pizza
A = RESULT
macroB foo, bar

if (A = 1) & (RESULT = 2)
...    


PS: Just a note, the preprocessing elements of the macros will be always long-circuited in the example above, if the "if" should affect the preprocessing stage then match has to be used instead.
Post 24 Dec 2009, 06:57
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
It would be so much easier to read and write it if I could do it in one line though.

Here's what I have so far (requires multiple lines!) and it doesn't even work Sad

Code:
macro varif [varMacro,<varArgs>,varCompareType,varCompareValue]{
       varIsTrue=1
forward
      varMacro        varArgs
     if result varCompareType varCompareValue
    else
                varIsTrue=0
 end if
common
}

varIf macroA,<blah,blahblah,pizza>,=,1,macroB,<foo,bar>,=,2
if varIsTrue
    


See it is two lines, it is really ugly, and it won't even compile.

Sad


This also doesn't work


Code:
macro   varif [varMacro,<varArgs>,varCompare]{
   varIsTrue=1
forward
      varMacro        varArgs
     if result varCompare
        else
                varIsTrue=0
 end if
common
}

varIf macroA,<blah,blahblah,pizza>,= 1,macroB,<foo,bar>,= 2
if varIsTrue
    

Please tell me what I'm doing wrong.. Confused


p.s. and yes I do set result in the macros

_________________
Post 24 Dec 2009, 07:06
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
I've no idea how you could do that but you might be interested in using 'match' in the varIF macro to get rid of all the commas...

have one parameter and use match to get the individual parameters, but you can define the separation with any symbol. you can use irp or irps to loop through them (though I don't think you'll need to).
Post 25 Dec 2009, 01:24
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.