flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > How work Define in match and if ?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 01 Apr 2023, 14:19
I not clearly understood how and when define applied in match branch.
Code:
macro some p {
 match x, p \{
      if x = 1      
      define _a2  50     ;What first fasm do if or define ?
      end if
      \}
}
;in code 
some 10 ;But why define _a2 applied ? If not working in this case.
    

And interesting, what first in macro fasm do if or define or equ ?
What is the execution order for if,equ, define ?
Post 01 Apr 2023, 14:19
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
revolution 02 Apr 2023, 01:20
Preprocessor runs first. Assembler runs later.

You can see this in the source fasm.asm
Code:
;...
        call    preprocessor
        call    parser
        call    assembler
        call    formatter
;...    
You can see the preprocessor names in the source tables.inc
Code:
preprocessor_directives:
 db 6,'define'
 dw define_symbolic_constant-directive_handler
 db 7,'include'
 dw include_file-directive_handler
 db 3,'irp'
 dw irp_directive-directive_handler
 db 4,'irps'
 dw irps_directive-directive_handler
 db 4,'irpv'
 dw irpv_directive-directive_handler
 db 5,'macro'
 dw define_macro-directive_handler
 db 5,'match'
 dw match_directive-directive_handler
 db 8,'postpone'
 dw postpone_directive-directive_handler
 db 5,'purge'
 dw purge_macro-directive_handler
 db 4,'rept'
 dw rept_directive-directive_handler
 db 7,'restore'
 dw restore_equ_constant-directive_handler
 db 7,'restruc'
 dw purge_struc-directive_handler
 db 5,'struc'
 dw define_struc-directive_handler
 db 0    
There is special handling for fix and equ in the preprocessor.
Code:
;...
        cmp     eax,'fix'
        je      define_fix_constant
;...
        cmp     eax,'equ'
        je      define_equ_constant
;...    
Other things like if, virtual, =, etc are in the assembler.
Post 02 Apr 2023, 01:20
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 02 Apr 2023, 07:45
preprocessor_directives
How I understood defined do first.
Post 02 Apr 2023, 07:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
revolution 02 Apr 2023, 07:54
Define is in the preprocessor.
Defined is in the assembler.

But despite the similar name they are not related in their function. They do not compliment each other.
Post 02 Apr 2023, 07:54
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 02 Apr 2023, 08:30
Ok.
For my case its good solution?
Code:
define ap 0
match x, P \{ 
If x eq for 
define ap a+ecx
End if
\}
;if I not control when define do. I simple check define
If ap = 0
Do variant 1
End if
If ap not 0
Do variant 2
End if    


And what is formatter in fasm? How work formatter?


Last edited by Roman on 02 Apr 2023, 08:38; edited 1 time in total
Post 02 Apr 2023, 08:30
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
revolution 02 Apr 2023, 08:38
If is in the assembler. So your define ap a+ecx is always processed if the match succeeds. The If x eq for is useless and does nothing.
Post 02 Apr 2023, 08:38
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 02 Apr 2023, 08:41
If x eq for useless.
Ok. How match finded Word for in p ?
Code:

match x =for, p {}?
    
Post 02 Apr 2023, 08:41
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
revolution 02 Apr 2023, 08:47
For the preprocessor version of "if" use "match".
Post 02 Apr 2023, 08:47
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
revolution 02 Apr 2023, 08:48
Do you want p (or P). matched to "for"?
Code:
match =for, p {
;...
}    
Post 02 Apr 2023, 08:48
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 02 Apr 2023, 09:12
match =for, p {} not working !
Code:
;compiled in fasmw 1.73
eggs equ for,8
;or eggs equ for 8
                ar = 0
                match =for, eggs { ar = 1 }
                match =run, eggs { ar = 2 }
                display ar+48,13,10 ;fasm show ar =0
    

This work fine !
Code:
macro uu p { ar = 0
match =for x, p \{ ar = 1
display 'match find for',13,10 \}     } 

eggs equ for,8
                uu eggs              
                display ar+48,13,10   ;show ar = 1               
                uu <for 11>
                display ar+48,13,10   ;show ar = 1

;this variant work too
macro uu p { define ar  0
match =for x, p \{ define ar  1
display 'match find for',13,10
\} } 
    
Post 02 Apr 2023, 09:12
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.