flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Checking if symbol is defined doesn't make it used?

Author
Thread Post new topic Reply to topic
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld 13 Aug 2011, 20:06
Is there a way to make code below work as expected? Suppose first `if` is a `proc` macro and second is written plain in code; proc could be defined in a separate file which in turn may or may not be included by filtering it out with `match` directive. What is expected is that output file is 8 (instead of 0) bytes.

Code:
if used x
  x dd 0
end if

if defined x
  y dd x
end if    
Post 13 Aug 2011, 20:06
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 16 Aug 2011, 16:09
Both 8-byte and 0-byte are the correct solutions to this source, so you have to play some tricks with fasm to make it choose a different route while resolving. Since "used" has default value FALSE when there is not enough information to make prediction, and this happens in the first pass, it chooses the "skip-if" route in the first pass and this leads to finding the 0-byte solution. You can, however, use this trick to make the first "if" block be assembled in the first pass:
Code:
if used x | ~defined @f
  x dd 0
end if
@@:

if defined x 
 a y dd x
end if    
As "defined" in the first pass has default value of FALSE, the "if" block gets assembled in the first pass and thus assembler finds the 8-byte solution.
Post 16 Aug 2011, 16:09
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.