flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Edited: No Bug with macro arguments enclosed in <...>

Author
Thread Post new topic Reply to topic
El Tangas



Joined: 11 Oct 2003
Posts: 120
Location: Sunset Empire
El Tangas
I don't think there are many bugs left in FASM, but here is one:

Code:
macro test [value] {
        forward
        define value 1#value

        forward
        db value
}


test 1h,2h,3h,4h,5h      


Works as expected, output is 11h 12h 13h 14h 15h

Code:
macro test [value] {
        forward
        define value 1#value

        forward
        db value
}


test 1h,<2h>,3h,4h,5h    


Works as expected, same output

Code:
macro test [value] {
        forward
        define value 1#value

        forward
        db value
}


test 1h,<2h,3h>,4h,5h    


Does not work as expected, invalid db,3h 12h,3h,3h is generated

Code:
macro test [value] {

        forward
        local mark
        define mark 1#value


        forward
        db mark
}


test 1h,<2h,3h>,4h,5h    


Works as expected, output is 11h 12h 03h 14h 15h


Last edited by El Tangas on 04 Jun 2015, 00:03; edited 1 time in total
Post 03 Jun 2015, 20:54
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
El Tangas
Quote:
invalid db,3h 12h,3h,3h is generated

Which is correct. Cause
define value 1#value
for the second macro argument is expanded into
define 2h,3h 1#2h,3h

This define in turn makes the second argument expand in db value, which is at first
db 2h,3h
, but after the define is applied becomes:
db ,3h 12h,3h,3h

_________________
Faith is a superposition of knowledge and fallacy
Post 03 Jun 2015, 22:45
View user's profile Send private message Reply with quote
El Tangas



Joined: 11 Oct 2003
Posts: 120
Location: Sunset Empire
El Tangas
Ah, ok thanks Very Happy Because of the comma being special. Well, I kind of suspected there was no bug Wink

However,

db,3h 12h,3h,3h

db ,3h 12h,3h,3h

are not the same string Wink

Well, fortunately I figured out the correct way of doing what I wanted to do in the final macro (I think Question )
Post 03 Jun 2015, 23:37
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
El Tangas
Quote:
However,

db,3h 12h,3h,3h

db ,3h 12h,3h,3h

are not the same string

These are the same for fasm. There are two alternatives for fasm to tokenize statements: one is at least one tab/space between tokens and another one is a symbol character, which becomes a separate token. In both cases it doesn't matter how many more tabs/spaces you put in between, the statement remains the same for fasm.

E.g., a|b is the same as a | b, but a!b is not the same as a ! b.

There's also one special case of backslash, which is a "half-symbol character", i.e. it always starts a new token unless it's directly preceded by another backslash and it never ends a current token.

P.S. There's also one case of strings that need a separate little explanation, but you can look it up in the documentation.

_________________
Faith is a superposition of knowledge and fallacy
Post 04 Jun 2015, 11:20
View user's profile Send private message Reply with quote
El Tangas



Joined: 11 Oct 2003
Posts: 120
Location: Sunset Empire
El Tangas
Ok, I've never looked very deeply into fasm macro language, tokenization and preprocessing, but I was trying to write less trivial stuff, so guess I'll have to.
Post 04 Jun 2015, 14:43
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 GitHub, YouTube, Twitter.

Website powered by rwasa.