flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > dynamic labels: differences between fasm and fasm2

Author
Thread Post new topic Reply to topic
tthsqe



Joined: 20 May 2009
Posts: 773
tthsqe 01 Apr 2026, 14:58
As far as I know, fasmg differs in that the symbol table can be dynamic, which got me thinking "How does fasm1 get away with a static symbol table?".
test.asm
Code:
a: db 1
db c.x
if 1
b: db 2
else
c: db 3,4
end if
.x:
db .x    

results
Code:
$ ~/fasm2/fasm2 test.asm test2.bin && hd test2.bin
flat assembler  version g.kl0e
test.asm [2]:
        db c.x
db? [15] (CALM)
Error: symbol 'c.x' is undefined or out of scope.

$ ~/fasm/fasm test.asm test1.bin && hd test1.bin
flat assembler  version 1.73.30  (16384 kilobytes memory)
2 passes, 4 bytes.
00000000  01 03 02 03                                       |....|
00000004    
Post 01 Apr 2026, 14:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20938
Location: In your JS exploiting you and your system
revolution 01 Apr 2026, 23:21
I think that is a bug in fasm,
Code:
org 9
b:
if 0
  c:
end if
.x:
db .x   ; okay   no error
db c    ; okay   error: undefined symbol 'c'.
db c.x  ; wot?   no error same as .x
db b.x  ; wot?   error: undefined symbol 'b.x'.    
c.x shouldn't exist, b.x should exist.
Post 01 Apr 2026, 23:21
View user's profile Send private message Visit poster's website Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 773
tthsqe 01 Apr 2026, 23:53
The only thing that I can say is possibly a bug in fasm1 here is that it failed to report that it's static analysis was insufficient, and therefore went on to produce something unexpected.
Post 01 Apr 2026, 23:53
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20938
Location: In your JS exploiting you and your system
revolution 02 Apr 2026, 00:15
It's been a bug (IMO) forever in fasm. It isn't fixable in its current form.

It happens because the label names are produced by the preprocessor stage, so "if 0" isn't considered at that stage, and "c" becomes the new base label for following labels. By the time the assembler stage runs the label name "c.x" has already been produced, and the information about it being created in the "if 0" block has been lost.

Note that label names (produced by the preprocessor stage) are separate from the values defined for them by the assembler stage.
Post 02 Apr 2026, 00:15
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8524
Location: Kraków, Poland
Tomasz Grysztar 02 Apr 2026, 15:46
fasm actually has another stage between the preprocessor and the assembler, it is the parser stage. See this description from 2003, and also this clarification from 2004. In short, the parser converts the preprocessed source into a bytecode that is then executed by the assembler repeatedly in a multi-pass process. Directive handlers and opcode generators are the "instructions" in this bytecode, and labels are converted to references (which are, in fact, direct pointers to the memory reserved for symbol structure).

This separation of stages was the architectural choice that allowed fasm to be fast, but I too recognized it as an architectural flaw, which is why my design for fasm2 (and its engine, fasmg) assumed no separate stages at the price of performance.

BTW, fasm's parser could in fact determine that "c:" label in your example could not be processed, because it detects when IF condition does not depend on any assembly-time variables. It optimizes such IF/ELSE blocks by discarding the condition and the code which would never be assembled. However I made it still process the labels in the discarded block, to make the behavior consistent. Therefore you can rely on IF having no effect on label naming in fasm - while it is a flaw, at least it is predictable.
Post 02 Apr 2026, 15:46
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-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.