flat assembler
Message board for the users of flat assembler.

flat assembler > Main > Space in macro parameters

Author
Thread Post new topic Reply to topic
Jin X



Joined: 06 Mar 2004
Posts: 54
Location: Russia
When I write:
Code:
macro popr [regs] { reverse pop regs }
popr ax bx cx dx    
fasm generates
Code:
pop ax
pop bx
pop cx
pop dx    

Why?
It works well only if I write
Code:
popr ax,bx,cx,dx    
(via comma)

How can I modify this code to use reverse pop with spaces?
Post 08 Jul 2018, 11:48
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6928
Location: Kraków, Poland
IRPS directive is there for this purpose.
Code:
macro popr [regs] { reverse irps reg,regs \{ \reverse pop reg \} }    

But if you need to also handle some multi-token operands, you may have to use MATCH.
Post 08 Jul 2018, 13:33
View user's profile Send private message Visit poster's website Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 54
Location: Russia
Thanks!
But now I cant use [ecx] or smth like this.
popr eax ebx [ecx]
Post 08 Jul 2018, 21:31
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6928
Location: Kraków, Poland
This what I mentioned, that for multi-token operands you'd have to do some MATCHing to tell the boundaries of operands. This in general is quite hard to do with the macros of fasm 1, here's a version that handles [ecx] syntax but no other variations:
Code:
macro popr [args] {
  common local list,more
  reverse
    define list
    define more 0
    irps token,args \{
      match =0 any, more list \\{
        list equ list,
      \\}
      list equ list token
      match [, token \\{
        define more 1
      \\}
      match ], token \\{
        define more 0
        \\}
    \}
    match ops,list \{
      irp op,ops \\{
        \\reverse popd op
      \\}
    \}
}    

Note that this kind of syntax in general is quite problematic and better avoided unless you can define a clear and simple rule that you are going to follow. Interpreting spaces as delimiters is a possible version of such rules, and as you can see in the mentioned thread it can be done with fasmg - unfortunately this is not possible in fasm 1, where the tokenizer does not leave any information about the whitespace in the stream of tokens it generates when reading line from the source.
Post 08 Jul 2018, 23:00
View user's profile Send private message Visit poster's website Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 54
Location: Russia
Thanks!
Post 09 Jul 2018, 16:27
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-2018, Tomasz Grysztar.

Powered by rwasa.