flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > [BUG?] virtual directive and labels prefixed with a dot

Author
Thread Post new topic Reply to topic
chris



Joined: 05 Jan 2006
Posts: 62
Location: China->US->China->?
chris
Hi, Tomasz I find a possible virtual directive bug.
Code:
        jmp     .label_1 ; ok
        jmp     .label_2 ; undefined symbol error

.label_1:

        virtual at eax
          p dd ?
        end virtual

.label_2: 
    

when compiling above code, I got undefined symbol error at "jmp .label_2", but for labels not prefixed with a dot or defined before the virtual directive, it is all right. It seems an opaque global label is defined by virtual and .lable_2 is attached to it. I am using fasm 1.67.5, could you look into this problme, thanks.
Post 21 Jul 2006, 03:20
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
"p" is a label too and since it is located between "jmp .label_2" and ".label_2:" .label_2 is out of scope for that JMP. To get access to it before the definition of "p" use p.label_2 (jmp p.label_2).

Regards
Post 21 Jul 2006, 03:25
View user's profile Send private message Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM
Or, you could change the definition of "p dd ?" to "..p dd ?" which would not make it change the current scope, but would allow it to be accessed globally as ..p
Post 21 Jul 2006, 17:15
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
But "p" is declared between "virtual" and "end virtual". Logically ".label_2" should not be attached to "p". In my opinion it is not maybe a bug, but unwanted bahaviour surely, and should be fixed.
Post 22 Jul 2006, 12:57
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
The behavior is very straightforward (and such defined in manuals): "local" label get attached to the nearest preceding it "global" label in the source (in the actual preprocessed source text). This gives the simple interpretation for the cases like:
Code:
a:
if x=3
 virtual
end if
 b dd ?
if x=4
 end virtual
end if
.c:    

or
Code:
a:
if x=3
 b:
end if
.c:    

The last label is "b.c" no matter how and whether the "b" gets actually defined. This is at least easily determinable and is utilized by some of the macros.

PS. The same goes for the anonymous labels (@@).
Post 22 Jul 2006, 13:32
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
PS. The same goes for the anonymous labels (@@).

interesting, never realized it:
Code:
jmp @f ;ERROR - undefined symbol
if 0
@@:
end if
@@:    
Post 24 Jul 2006, 06:55
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
chris



Joined: 05 Jan 2006
Posts: 62
Location: China->US->China->?
chris
Quote:
"p" is a label too and since it is located between "jmp .label_2" and ".label_2:" .label_2 is out of scope for that JMP. To get access to it before the definition of "p" use p.label_2 (jmp p.label_2).


yes, that's what I thought where the problem is.

Quote:
Or, you could change the definition of "p dd ?" to "..p dd ?" which would not make it change the current scope, but would allow it to be accessed globally as ..p


I just did it in my source to void this conflicts, and use .p also works in this case.

Quote:
But "p" is declared between "virtual" and "end virtual". Logically ".label_2" should not be attached to "p". In my opinion it is not maybe a bug, but unwanted bahaviour surely, and should be fixed.


That's what I originally wanted to say, I used the virtual directive to define some lable to access the data field of a struct, and when compiling, I got the error, so, may be we should usually use double-dotted lables inside virtual directives.

Quote:
The behavior is very straightforward (and such defined in manuals): "local" label get attached to the nearest preceding it "global" label in the source (in the actual preprocessed source text). This gives the simple interpretation for the cases like:


Quote:

[/code]
jmp @f ;ERROR - undefined symbol
if 0
@@:
end if
@@:
[/code]


thank you guys, got it. Very Happy [/code]
Post 25 Jul 2006, 09:58
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.