flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > not work if. with include

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1938
Roman 05 Apr 2025, 15:33
fasmw 1.73
Code:
macro level nameFile,[b] { if b > 0
include nameFile#`b#'.txt'
end if
}
;in code
level 'a',0 ;fasm error file not found. I want ignored file if b=0
    
Post 05 Apr 2025, 15:33
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 05 Apr 2025, 19:36
Code:
macro level n*, [b] { match =0, b \{ include n\#\`b\#'.txt' \} }    
Post 05 Apr 2025, 19:36
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1938
Roman 05 Apr 2025, 19:47
level 'procs\a',2 ;not do include
level 'procs\a',0 ;file not found.
Code:
;must be:
level 'procs\a',0 ;not include any file.
level 'procs\a',2,1 ;must do include file 'procs\a2.txt' and file 'procs\a1.txt'    
Post 05 Apr 2025, 19:47
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 05 Apr 2025, 21:43
Code:
macro level n*, [b] { match =0, b \{ rept 0\{ \} rept 1 \{ include n\#\`b\#'.txt' \}}    
Post 05 Apr 2025, 21:43
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20625
Location: In your JS exploiting you and your system
revolution 05 Apr 2025, 22:51
This is the assembler vs preprocessor paradigm again.

include is preprocessor, runs before the assembler.
if is assembler, runs after preprocessor.
Post 05 Apr 2025, 22:51
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1938
Roman 06 Apr 2025, 04:43
Quote:

include is preprocessor, runs before the assembler.
if is assembler, runs after preprocessor.

How understand include do first.
But if condition could undo include.
That's the collusion\collision.

for example:
Code:
aa=0
if aa>0
include 'code1.txt' ;not included file
end if
    


question: include get error. Exist method clear error ?
something err=0.
for example: include 'a0.txt' get error file not found.
clear error and fasm continues to compile code.
Code:
include 'a0.txt' ;get error file not found.
clearError ; fasm continues to compile  code and ignored prevision error.

clearError very useful for macro.
    
Post 06 Apr 2025, 04:43
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20625
Location: In your JS exploiting you and your system
revolution 06 Apr 2025, 05:41
The file is included, but the if makes all the code inside not assemble.
Code:
if 0
 ; anything in here is not assembled, ordinary lines and included files
end if    
Just pretend that any included files are copy-pasted into the source.
Post 06 Apr 2025, 05:41
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1938
Roman 06 Apr 2025, 06:12
That's is confused.
Because:
Quote:
include is preprocessor, runs before the assembler.
if is assembler, runs after preprocessor.
Post 06 Apr 2025, 06:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20625
Location: In your JS exploiting you and your system
revolution 06 Apr 2025, 06:32
Being assembled is a different stage from included (by the preprocessor). Files are still included, no matter the result of the condition.

The preprocessor blindly includes all the files, later the assembler evaluates the conditions and decides whether to assemble or not.
Post 06 Apr 2025, 06:32
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: 20625
Location: In your JS exploiting you and your system
revolution 06 Apr 2025, 06:36
Try this:
Code:
if 0
 include 'thing.inc'
 ;inside thing.inc:
 ; thing equ 1
end if
if thing = 1
 display "thing is set"
end if    
output:
Code:
flat assembler  version 1.73.31  (16384 kilobytes memory)
thing is set
1 passes, 0 bytes.    
include and equ are preprocessor, so they always get processed, no matter the if condition result.
Post 06 Apr 2025, 06:36
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 06 Apr 2025, 09:13
Code:
ky1 = 0
ky2 = 0
ky3 = 0
if 0
  include 'my.inc'
  ; my.inc:
  ; ch1 equ 1
  ; ky1 = 1
  ; display 'No message!', 13, 10
  ; end if
  ; ch2 equ 1
  ; ky2 = 1
  ; display 'Ha ha!!!', 13, 10
  ; if 0
  ; ch3 equ 1
  ; ky3 = 1
  ; display 'No message, too!', 13, 10
end if
if ch1 = 1
  display 'CH1', 13, 10
end if
if ch2 = 1
  display 'CH2', 13, 10
end if
if ch3 = 1
  display 'CH3', 13, 10
end if
if ky1 = 1
  display 'KY1', 13, 10
end if
if ky2 = 1
  display 'KY2', 13, 10
end if
if ky3 = 1
  display 'KY3', 13, 10
end if

; $ fasm ch.inc
; flat assembler  version 1.73.32  (16384 kilobytes memory, x64)
; Ha ha!!!
; CH1
; CH2
; CH3
; KY2
; 1 passes, 0 bytes.    
Post 06 Apr 2025, 09:13
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20625
Location: In your JS exploiting you and your system
revolution 07 Apr 2025, 02:23
Not just for if, but all assembler constructs mean nothing to the preprocessor.
Code:
if 0
  repeat 0
    while 0
      display 'cannot see me',10
      foo equ 1
    end while
  end repeat
end if

if foo
  display 'foo was processed',10
end if    
Code:
flat assembler  version 1.73.31  (16384 kilobytes memory)
foo was processed
1 passes, 0 bytes.    
Post 07 Apr 2025, 02:23
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.