flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > to dot or not to dot

Author
Thread Post new topic Reply to topic
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 10 Mar 2006, 10:39
i swear i read pdf! Rolling Eyes
i noticed it far ago...
if you declare any macro in this way:
Code:
macro dot1
{
    je .dot
    nop
.dot:
}    
    

and will use it in such place:
Code:
proc proc1
    je .finish
    dot1
    dot1
.finish:
    ret
endp
    

you will get this:
Code:
e:\projects\DOT\DOT.asm [41]:
    dot1
e:\projects\DOT\DOT.asm [13] dot1 [3]:
.dot:
error: symbol already defined.
    
..........
for this:
Code:
macro dot3
{
    local dot
    je dot
    nop
dot:
}        
proc proc2
    je .finish
    dot3
.finish:
    ret
endp    
you will got this:
Code:
e:\projects\DOT\DOT.asm [53]:
    je .finish
error: undefined symbol.
    
only this works proper to me:
Code:
macro dot2
{
    local .dot
    je .dot
    nop
.dot:
}          
    

_________________
UNICODE forever!
Post 10 Mar 2006, 10:39
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 10 Mar 2006, 12:29
of course... btw, most proper way is dot to dot:
Code:
macro dot2 
{ 
    local ..dot 
    je ..dot 
    nop 
..dot: 
}    
Post 10 Mar 2006, 12:29
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 10 Mar 2006, 13:07
this also ok, but in pdf written:
...label whose name begins with dot is treated as local label, and its name is attached to the name of last global label (with name beginning with anything but dot) to make the full name of this label. So you can use the short name (beginning with dot) of this label anywhere before the next global label is defined,..
...
...local directive defines local names, which will be replaced with unique values each time the macroinstruction is used. It should be followed by names separated with commas. 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. This directive is usually needed for the constants or labels that macroinstruction defines and uses internally. For example:
Code:
macro movstr
 {
    local move
   move:
    lodsb...    
with examples above it is not clear: is "move" local label or global. i do not say it is wrong work of compiler, but it should be desribed more clear, i think.
Post 10 Mar 2006, 13:07
View user's profile Send private message Visit poster's website Reply with quote
chris



Joined: 05 Jan 2006
Posts: 62
Location: China->US->China->?
chris 10 Mar 2006, 14:14
Hi, shoorick

As stated in the manual, label begins with a dot is attached to the last global label, and this is done at assembling time. for example:
Code:
macro dot1
{ 
    je .dot 
    nop 
.dot: 
}     

global1:
    dot1
global2:
    dot1
    

after preprocessing becomes:
Code:

;macro dot1
;{
; je .dot
; nop
; .dot:
;}

global1:
;dot1
        
        je .dot
        nop
        .dot:
        
global2:
;dot1
        
        je .dot
        nop
        .dot: 
    

and it gets assembled correctly. When local directive is used to define a lable in macro, again, as stated in manual, a unique lable is generated each time the macro is expanded, for instance:
Code:
macro dot2
{
    local dot
    je dot
    nop 
dot:
}

dot2
dot2 
    

after preprocessing becomes:
Code:
;macro dot2
;{
; local dot
; je dot
; nop
; dot:
;}

;dot2
        
        ; dot?0000000
        je dot?0000000
        nop
        dot?0000000:
        
;dot2
        
        ; dot?0000001
        je dot?0000001
        nop
        dot?0000001:
    

Note that two labels are generated by the preprocessor.
Look in the FAQ for the fasm preprocessor tool. If you are using 1.65 package, look at here http://board.flatassembler.net/topic.php?t=4761 for the tweak. Smile
Post 10 Mar 2006, 14:14
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 10 Mar 2006, 14:31
then "local" directive defines global unic label, if it is not started with dot, or unic local, if it started with dot, as i understand (?) this should be specified (?)
thnx for example - i'll look there lately Smile
regards!
Post 10 Mar 2006, 14:31
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 11 Mar 2006, 13:53
local has nothing to do with local labels, though they use the same word. Wink
Post 11 Mar 2006, 13:53
View user's profile Send private message Reply with quote
Ancient One



Joined: 28 Feb 2005
Posts: 55
Ancient One 19 Mar 2006, 05:46
local is a preprocessor directive that ONLY defines a unique label, not necessarily global/local. only the presence of dot (single/double/nothing) in front of label will determine its scope. So if you use local like
Code:
macro foo {
 local bar
 bar:
}
foo
    

it will define unique, normal label
but with
Code:
macro foo {
 local .bar
 .bar:
}
foo
    

it will define unique, local label
and with
Code:
macro foo {
 local ..bar
 ..bar:
}
foo
    

will define unique, global label
Post 19 Mar 2006, 05:46
View user's profile Send private message MSN Messenger 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.