flat assembler
Message board for the users of flat assembler.

Index > Main > GAS-like anonymous labels.

Author
Thread Post new topic Reply to topic
Jeronimus Linuxius



Joined: 28 Jun 2007
Posts: 37
Jeronimus Linuxius 28 Jun 2007, 23:50
Is it possible to use gas-like anonymous labels in fasm?

They work similary to fasm anonymous labels, but you can define multiple instances of them... For example, look at the following code:
Code:
cmp ax, bx
je equal
;Do something (if different)
jmp @f
equal:  ;Do something
@@:
;Continue
    


It's basically a normal if-then-else structure... but in asm... And in fasm we are required to define at least one non-anonymous label, thus polluting the name space (which can be a problem if my function has many constructs like this one).

In gas, I would do:
Code:
cmpw %ax, %bx
je 1f
#Do something (if different)
jmp 2f
1:  #Do something
2:
#Continue
    

(The important thing here is not the AT&T syntax idiosyncrasies, but the anonymous label syntax)

As you can see, in gas we avoid defining a label when we have this kind of constructs. This can be important if we want to put this code in a macro or so, but that doesn't matter in the case... I don't like to define macros that subvert the language semantics... My problem is name-space pollution, which is sometimes difficult to manage.
There is also the problem of when I don't know what name to give to the label. Namely because the algorithm is excessively generic or self-explanatory. In nasm I always kept naming the labels as ".loop1", ".loop2", ".loop3", etc, and I think that's not very comfortable to just give systematic names to labels... I'm not a compiler!


I've read some parts of fasm manual, primarily the parts related with the preprocessor, but I found no ideal way to implement this in the code's side.
I thought I could write a macro to define a GAS-style anonymous label (taking the number as an argument), and then a macro to access the last, or the following, label defined with a given number.
The approach I thought about was defining a preprocessor variable with the name of the last systematic name created by the preprocessor. Then, the name of the following "version" of the label would be found through concatenation (because the preprocessor is unable to do calculations, remember?). The only problem I found is that we can't ask the preprocessor to behave differently whether a constant is defined or not. This is possible with the assembler, but not with the preprocessor.


Besides, I've thought about an alternate way to solve the above problem. What about a special symbol called "@ff", meaning the second anonymous label counting from here.

JJ
Post 28 Jun 2007, 23:50
View user's profile Send private message MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 28 Jun 2007, 23:52
this has been discussed several times already, try searching forum. "@ff" would be a good search query Wink
Post 28 Jun 2007, 23:52
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Jeronimus Linuxius



Joined: 28 Jun 2007
Posts: 37
Jeronimus Linuxius 29 Jun 2007, 18:33
vid wrote:
this has been discussed several times already, try searching forum. "@ff" would be a good search query ;)


I hadn't noticed that...

Anyway, no one seems to be aware of GAS' way, which I think is very reasonable (and perhaps easier to implement).

JJ
Post 29 Jun 2007, 18:33
View user's profile Send private message MSN Messenger Reply with quote
Jeronimus Linuxius



Joined: 28 Jun 2007
Posts: 37
Jeronimus Linuxius 29 Jun 2007, 18:41
Jeronimus Linuxius wrote:
Anyway, no one seems to be aware of GAS' way, which I think is very reasonable (and perhaps easier to implement).


Searches for "anonymous GAS" and "GAS label", with the option to match all words turned on returns only this thread.

JJ
Post 29 Jun 2007, 18:41
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.