flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > How to get the label in front of a macro

Author
Thread Post new topic Reply to topic
PaoloR



Joined: 04 Nov 2010
Posts: 2
PaoloR 04 Nov 2010, 21:02
I need to get the label in front of the macro if any. In NASM you can use the %00 built in variable. I checked the FASM manual but I could not find anything equivalent. It does not have to be something similar as long as I can get that label.

For clarity, this is an example:

mylabel: MYMACRO p1,p2

I would like to access the string/label "mylabel" from the within the macro.

Thanks in advance
Post 04 Nov 2010, 21:02
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 04 Nov 2010, 21:11
fasm uses a "struc" directive for such purpose, which is a special kind of macro that need to have a label before it. Also you do not add colon between the label and name of struc macro, just like you do not put colon between the label and data definition directive (like "mydata DB 1"). The struc label can be accessed with "." name. You use it like this:
Code:
struc MYMACRO p1,p2
{
   . = p1*p2
}

mylabel MYMACRO 7,6

; ...

        mov     al,mylabel ; should be 42    
Post 04 Nov 2010, 21:11
View user's profile Send private message Visit poster's website Reply with quote
PaoloR



Joined: 04 Nov 2010
Posts: 2
PaoloR 04 Nov 2010, 21:32
Tomasz: Thanks for the quick reply. I need access to the label to implement LEAVE and ITERATE (break and continue in the C/Java world). When there are multiple nesting of, say LOOP, I would like to sometimes to target an outer LOOP instead of the inner LOOP. That is the reason I need access to the label, but not always.

So the LOOP macro would have an optional label in front of it, that could be the target of the LEAVE or ITERATE.

From your message I am not sure I can do it with a struct type macro since struct always requires a label.

Thanks again
Post 04 Nov 2010, 21:32
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 05 Nov 2010, 08:54
PaoloR,

macro wrapper for struc is easy to implement. Moreover, macro versions of leave/iterate could take shortcuts if handling for innermost and other nesting levels is different.
Post 05 Nov 2010, 08:54
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.