flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Local labels interfere with naming space

Author
Thread Post new topic Reply to topic
pfranz



Joined: 13 Jan 2007
Posts: 116
Location: Italy
pfranz 22 Nov 2023, 16:35
Local macro labels shouldn't affect naming space, but they do:
Code:
macro m {
local a
a:
}

b:
jmp .c

m

.c:    
Here, the local label "hides" .c and this code doesn't assemble.
Post 22 Nov 2023, 16:35
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 913
Location: Russia
macomics 22 Nov 2023, 17:08
Code:
macro m {
local a
a:
}

b:
jmp .c

m

b.c:    
or
Code:
macro global name* {
  if 0
    label name
  end if
}
macro m {
local a
a:
}

b:
jmp .c

m

global b
.c:    
Post 22 Nov 2023, 17:08
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8344
Location: Kraków, Poland
Tomasz Grysztar 22 Nov 2023, 18:28
Section 2.3.3 of the manual wrote:
If the name given as parameter to LOCAL directive begins with a dot or two dots, the unique labels generated by each evaluation of macroinstruction will have the same properties.
Keep in mind that in fasm 1.x architecture preprocessor is a separate stage with its own language, converting entire source before the assembler has a chance to see it (and it is the assembly parser that then interprets properties of labels, like the starting dot). The labels produced in the text of a macro are no different from any other labels during the assembly stage. See the output of PREPSRC tool to get an idea of what text the assembler sees.

If you would prefer an assembler with single, unified language, there is fasmg, fasm's successor. It has proper separation of namespaces and symbols local to macros do not interfere with the other ones.
Post 22 Nov 2023, 18:28
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: 20118
Location: In your JS exploiting you and your system
revolution 22 Nov 2023, 21:55
Use the double dot.
Code:
macro m {
local ..a
..a:
}    
Post 22 Nov 2023, 21:55
View user's profile Send private message Visit poster's website Reply with quote
pfranz



Joined: 13 Jan 2007
Posts: 116
Location: Italy
pfranz 24 Nov 2023, 02:37
That's what I do, I use one or two dots, but I just found notable that local labels would interfere outside their macros.
Two dots perfectly solve the problem.
Post 24 Nov 2023, 02:37
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20118
Location: In your JS exploiting you and your system
revolution 24 Nov 2023, 02:46
local just creates a unique name, it doesn't make any sort of special label.
Code:
~ cat test.asm 
macro m {
        local a
        display `a,10
}
rept 16 {m}

~ fasm test.asm 
flat assembler  version 1.73.31  (16384 kilobytes memory)
a?0
a?1
a?2
a?3
a?4
a?5
a?6
a?7
a?8
a?9
a?A
a?B
a?C
a?D
a?E
a?F
1 passes, 0 bytes.
~     
Post 24 Nov 2023, 02:46
View user's profile Send private message Visit poster's website Reply with quote
pfranz



Joined: 13 Jan 2007
Posts: 116
Location: Italy
pfranz 24 Nov 2023, 02:53
In my opinion there shouldn't be any special label, it should just be separated from the "outside world" (hence the word "local"). Like this is "semi-local".
Anyway there is no practical problem, another solution is to use:

a = $

instead of

a:
Post 24 Nov 2023, 02:53
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.