flat assembler
Message board for the users of flat assembler.

Index > Main > label in a macro question

Author
Thread Post new topic Reply to topic
sgdt



Joined: 08 May 2009
Posts: 3
sgdt
I am porting some code written in ML64 to FASM, and aside from the usual issues, I'm having a problem with labels. I'm including a simplistic reproduction of the issue.

Code:
macro   A
{
        local   L_A
        jmp     L_A
L_A:    ret
}

macro   B
{
       jmp     L_A
.L_A:    ret
}

macro   C
{
       jmp     @f
@@:    ret
}

macro   D
{
        repeat 5
               C
        end repeat
}

macro   Root
{
        repeat 5
                D         ; This can be A / B / D for errors.
        end repeat
}

proc Fred
     Root
endp
    


If macro Root (inside repeat loop) is A, B, or D, it generates multiple duplicate label errors.

From reading the documentation, I had first tried (just like MASM) to use LOCAL, then saw the comments about "." leading label names being private, and finally resulted to trying the '@@' anonymous labels, but can't get any of them to work for this.

I've also tried things other than repeat (like rept, etc).

Please note: The above is heavily simplified to illustrate the issue I'm running into. I *need* to use repeat (rept, etc.) inside of macros and be able to use macros with labels.

I also need to get this to worth with FASM (as compared to the asms that have weird syntaxes and don't support macro parameter names).

Thank you in advance for any assistance with this issue.
Post 08 May 2009, 22:05
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
When you replace "repeat" with "rept", the "A" and "C" variants will work correctly
Code:
macro   A
{ 
        local   L_A 
        jmp     L_A 
L_A:    ret 
} 

macro   C 
{ 
       jmp     @f 
@@:    ret 
} 

macro   D 
{ 
        rept 5
        \{
               A
               C 
        \}
}

D    

The feature you tried to use in "B" comes from NASM syntax and should be used differently. Since you come from MASM, I suggest you ignore it for now.
Post 08 May 2009, 22:36
View user's profile Send private message Visit poster's website Reply with quote
sgdt



Joined: 08 May 2009
Posts: 3
sgdt
Thank you for your assistance.
As I mentioned, I had tried rept, but still had an issue:

Code:
macro   Root
{
        rept 21
        \{
                local label
                label: loop label
        \}
}

proc Fred
        Root
        ret
endp
    


The above is identical to documentation, except it's in a macro.

Anyway, FASM seems to be a great asm. I've gotten around the issue by using the "irp" directive, which doesn't seem to have the problem. This particular piece of code makes very heavy use of embedded macros within macros with pre-processed loops, generates about 1MB object (which will double when the non-SSSE3 codepath is put in place). Gota love video...

Thank you.
Post 09 May 2009, 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: 17667
Location: In your JS exploiting you and your system
revolution
You have to "escape" the local directive also:
Code:
macro   Root
{
        rept 21
        \{
                \local label ;<--- escape with a backslash
                label: loop label
        \}
}    
Post 09 May 2009, 02:46
View user's profile Send private message Visit poster's website Reply with quote
sgdt



Joined: 08 May 2009
Posts: 3
sgdt
I would never have thought to try that...

Thank you very much!
Post 09 May 2009, 03:15
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 GitHub, YouTube, Twitter.

Website powered by rwasa.