flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Unable to compile code

Author
Thread Post new topic Reply to topic
thetrick



Joined: 19 Feb 2020
Posts: 8
thetrick
Hello everyone!

Why can't i compile the following code (FASM)?

Code:
;seed = 1234

if ~defined seed
   seed = %t
end if

db 0xe8
dd seed        


If i unncomment the first line it works.
Post 25 Aug 2021, 20:29
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7938
Location: Kraków, Poland
Tomasz Grysztar
There is a very recent thread about this: https://board.flatassembler.net/topic.php?t=21977 (it applies to fasm g as well as fasm 1, they both handle it the same way).
Post 25 Aug 2021, 20:47
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 394
Location: Ukraine
Overclick
Quote:

There is a very recent thread about this

Why don't you fix this for intuitive logic? A lot of macro ideas just stack for this issue. I know how to avoid some of it but isn't it better to use it as it must to be used?
Post 26 Aug 2021, 07:30
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: 18220
Location: In your JS exploiting you and your system
revolution
We can make a macro to simulate the redefinition:
Code:
macro default_val var, value {
        local seen_already
        if ~ defined var | defined seen_already
                var = value
                seen_already = 0
        end if
}

; seed = 1234
default_val seed, %t

db 0xe8
dd seed    
Post 26 Aug 2021, 08:20
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7938
Location: Kraków, Poland
Tomasz Grysztar
I should have started with a simpler answer: just use DEFINITE instead of DEFINED, it does exactly what you meant to do here (while DEFINED does not).

Overclick wrote:
Why don't you fix this for intuitive logic? A lot of macro ideas just stack for this issue. I know how to avoid some of it but isn't it better to use it as it must to be used?
My attempt to "fix" it was to introduce DEFINITE operator, complementing DEFINED.

You should use DEFINED when you need to check whether the symbol has a defined value, no mater where, it allows to ensure that you can use it (because you can use a symbol through forward reference even if it is defined later). And DEFINITE can check whether the symbol has been defined earlier in the source, what you might need to check before trying to define it again.

They are logically different checks and both are needed - though in a language not having forward-references they would be one and the same. This is perhaps the reason why "if ~ defined" in fasm may appears counterintuitive - because having unrestricted ability to refer to symbols no matter whether they are declared later is perhaps unusual. But this is one of the cornerstones of fasm's language and one of its strengths, and you may notice that when I designed fasmg as a successor, I doubled down and went even further - there you can forward-reference almost anything, including macros of output content.
Post 26 Aug 2021, 08:54
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.