flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Prolem using match to define enum macro

Author
Thread Post new topic Reply to topic
chris



Joined: 05 Jan 2006
Posts: 62
Location: China->US->China->?
chris
Hi, All
Happy Luna New Year(Chinese New Year)!Very Happy

I was trying to define the enum macro in this way:
Code:
macro enum name*,[item]
{
   common
        local count
        count=0
   forward
        item=count
        count=count+1
}
    


It works well if I just want to use enum in the way like
Code:
enum    SYSTEM_INFORMATION_CLASS,\
        SystemBasicInformation,\                ; 0        Y        N
        SystemProcessorInformation,\            ; 1        Y        N
        SystemPerformanceInformation,\          ; 2        Y        N
        SystemTimeOfDayInformation,\            ; 3        Y        N
        SystemNotImplemented1,\                 ; 4        Y        N
        SystemProcessesAndThreadsInformation,\  ; 5        Y        N
        SystemCallCounts,\                      ; 6        Y        N
        SystemConfigurationInformation         ; 7        Y        N
    


then I want to extend this definition such that the following declaration works
Code:
enum Week,\
         Sun=7,\
         Mon=1,\
         Tue,\
         Wed,\
         Thu,\
         Fri,\
         Sat
    


such that Sun=7 and Mon=1, Tue=2... I changed enum definition as follows but it does not work.Sad
Code:
macro enum name*,[item]
{
   common
        local count
        count=0
   forward
        match nam==val,item
        \{
                nam=val
                count=val+1
                ; I want to skip the following statements 
                ; and goto process the next parameter item 
                ; from here, but I don't know how.
        \}
         
        item=count
        count=count+1        
}  
    


Is there a preprocessing directive like 'continue','goto' or match...else... ?
thanks in advance.
Post 29 Jan 2006, 11:18
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
Read my last post here: http://board.flatassembler.net/topic.php?t=4638 (the macros that use the "status" variable) for some general information.

However in your case it would be enough to do it this way:
Code:
macro enum name*,[item]
{
   common
        local count
        count=0
   forward
        processed = 0
        match nam==val,item
        \{
                nam=val
                count=val+1
                processed = 1
        \}
        if ~ processed
           item=count
           count=count+1
        end if
}    

or even some a bit tricky one:
Code:
macro enum name*,[item]
{
   common
        local count
        count=0
   forward
           if 1
        match nam==val,item
        \{
                nam=val
                count=val+1
           else
        \}
                item=count
                count=count+1
           end if
}    
Post 29 Jan 2006, 12:28
View user's profile Send private message Visit poster's website Reply with quote
chris



Joined: 05 Jan 2006
Posts: 62
Location: China->US->China->?
chris
thanks Tomasz, that's great. now I have a better understanding of fasm's preprocessing from your second example. So the preprocessor operates on text, and we can construct proper commands at preprocessing stage and pass them to assembler. Thanks again. Smile

I think following is the pseudo-preprocessing procedure: is it correct?

Code:
enum week, Sun=7,Mon=1,Tue
    


after preprocessing becomes:

Code:
count=0

if 1
  Sun=7
  count=7+1
else
  Sun=7=count ; although it is invalid expression, but the assembler skips it
  count=count+1
end if

if 1
  Mon=1
  count=1+1
else
  Mon=1=count
  count=count+1
end if

if 1
  Tue=count
  count=count+1
end if
    
Post 30 Jan 2006, 05:45
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
Yes, exactly.
Please look also into Macroinstruction FAQ, you can find there a thread with a tool to save the result of preprocessing in a text file - which you could use to validate your predictions.
Post 30 Jan 2006, 08:49
View user's profile Send private message Visit poster's website Reply with quote
chris



Joined: 05 Jan 2006
Posts: 62
Location: China->US->China->?
chris
thanks Tomasz, FASMPRE is the ultimate tool to learn fasm macros. Wink
Post 30 Jan 2006, 12:20
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.