flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Macroinstructions > [fasmg] & after parameter is ignore by match

Author
Thread Post new topic Reply to topic
zhak



Joined: 12 Apr 2005
Posts: 479
Location: Belarus

[fasmg] & after parameter is ignore by match

It looks like match discards the meaning of & character for macro parameter name

Code:

macro mymacro args&
  local arguments
  define arguments args
  match (xmoreargs
    redefine arguments more
  end match
  irp argumentarguments
    match a-bargument
      display `a
    end match
  end irp
end macro

mymacro (5hello-worldsweet-buns



more contains part of parameter to the first comma only, but I'd like it to stay the whole string, not be split into different params. How can I achieve this?
Post 09 Apr 2017, 22:24
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6686
Location: Kraków, Poland

If you display `b instead of `a you may notice that it contains the "world, sweet-buns" text, nothing was lost. The problem here is that IRP does not evaluate symbolic constant in its arguments, so there is only one iteration and "argument" simply has value "arguments", which is later evaluated by MATCH. To process the list correctly you may need to do something like:

Code:
  match list,arguments
   irp argumentlist
     match a-bargument
       display `a
     end match
   end irp
  end match

Post 09 Apr 2017, 22:38
View user's profile Send private message Visit poster's website Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 479
Location: Belarus

ah, sure, should have guessed about evaluating with match Sad Thanks! fasmg is so complex, yet so much fun!
Post 09 Apr 2017, 22:50
View user's profile Send private message Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 479
Location: Belarus

So, if a value is referenced by macro argument name (args), it gets evaluated inside macro and irp works fine. But using "define"/"redefine" I just created a link to what is contained in "more" and it is not evaluated. In order to evaluate value defined with "define", I should use "match". am I right?
Post 09 Apr 2017, 22:56
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6686
Location: Kraków, Poland

Macroinstruction arguments and all parameters in general (because "argument" defined by IRP is also a parameter of the same kind as argument to macro) are replaced with their value text before processing each line. So for example you can do things like:

Code:
irp statementx = 'OK'display xrestore x
        statement
end irp


On the other hand symbolic variables are regular expression-class symbols just like numeric ones, and they are only evaluated inside expressions. It obviously needs to be this way, because if the symbolic variables were replaced with their values before processing a line you would not even be able to re-define such variable - if in statement like "a equ b" the "a" was replaced with its value you could end up with a completely different instruction.

In addition to evaluating them in expressions (numeric and logical ones) symbolic variables are also processed in two special cases - in the value of EQU definition and in the second argument of MATCH. This is inherited from fasm 1, since it worked out there.

There is in fact a strong analogy between these rules and the operation of preprocessor in fasm 1. There replacement of symbolic variables occurred only after the preprocessor interpreted the line and found no instruction for itself to execute, so any preprocessor directives were not affected, including ones like IRP. And the only two special places where this replacement was done in the text of such directives were the second arguments to EQU and MATCH.

As for the methods of converting a value of symbolic variable to a preprocessed parameter, there are two, both mentioned in the fasmg manual. One is with IRPV and the other one with MATCH.
Post 10 Apr 2017, 07:35
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6686
Location: Kraków, Poland


zhak wrote:
fasmg is so complex, yet so much fun!

I'm glad to hear that I'm not the only one who finds it fun. Smile
Post 10 Apr 2017, 07:42
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2017, Tomasz Grysztar.