flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [fasmg] question about matching

Author
Thread Post new topic Reply to topic
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 12 Feb 2017, 15:52
Let's say I define data types as
Code:
byte      ; the same as rb 1
byte [?] ; the same as rb 1
byte [3] ; the same as rb 3
byte [4] 5 ; the same as db 4 dup 5
etc.
    

Also, I add naturally aligned data types as
Code:
aligned word
aligned dword [4]
etc.
    


For this aligned types I use struc
Code:
struc aligned? args&
  match =byte?, args
    label .
    byte [1]
  else match =byte? more, args
    label .
    byte more
  else match =word?, args
    align 2
    label .
    word [1]
  else match =word? more, args
    align 2
    label .
    word more
  end match
end struc
    

Here I must always match two variants: if data type has parameters following it or not.
Is it possible to somehow match only the beginning of the string so that it doesn't matter if 'more' is empty or not?
Post 12 Feb 2017, 15:52
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 12 Feb 2017, 16:14
zhak wrote:
Is it possible to somehow match only the beginning of the string so that it doesn't matter if 'more' is empty or not?
While MATCH does not allow to match names with empty content, it is usually possible to deal with this using some tricks, though that may depend on context. For example:
Code:
    match =word? more, args :
        align 2
        label .
        match value :, more
                word value
        else
                word [1]
        end match
    end match    
Post 12 Feb 2017, 16:14
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.