flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > How to distinguish the label and constant?

Author
Thread Post new topic Reply to topic
CandyMan



Joined: 04 Sep 2009
Posts: 311
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan
How to distinguish the label and constant?
Code:
ThisIsConst = 10

ThisIsLabel:

        if ThisIsLabel eqtype 0
        end if
    

_________________
smaller is better
Post 17 Jan 2013, 13:43
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
CandyMan,

Not an easy task (they're so closely related). The most I can offer to try is relativeto operator and object output format.
Code:
format COFF
ThisIsConst = 10
ThisIsLabel:

if ThisIsConst relativeto $
  display "Label"
else
  display "Constant"
end if    
Post 17 Jan 2013, 15:44
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
Strange request - for what do you need it exactly ?

You should know if you define a label or a constant. Very Happy
Post 17 Jan 2013, 18:55
View user's profile Send private message Send e-mail Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 311
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan
Thanks!
Post 18 Jan 2013, 13:19
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
shutdownall wrote:
Strange request - for what do you need it exactly ?
For a macro maybe?
Post 19 Jan 2013, 16:08
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
revolution,

Surely for a macro (but if doesn't fit well). There should be some synergy between preprocessor and interpreter (at least we have rept for some calc), probably in 2.0 it'll prosper wildly. Wink
Post 19 Jan 2013, 19:28
View user's profile Send private message Reply with quote
seapoint



Joined: 25 May 2013
Posts: 8
seapoint
Recently I had a similar problem, but I wanted to discern between normal labels and everything else. The simplest way is just to use regexp in python

Code:
import sys, re

def main(argv):
    if len(argv) < 3:
        print "usage: %s <source asm> <output asm>" % argv[0]
    else:
        output_file = open(argv[2], 'w')
        input_file = open(argv[1], 'r')
        out = add_labels(input_file.read())
        output_file.write(out)

def add_labels(source):
    labels = [label[:-1] for label in re.findall("\w+:", source)]
    return "_ALL_LABELS equ %s\n" % ",".join(labels) + source 

if __name__ == "__main__":
    main(sys.argv)

    


then you can just use if arg in <_ALL_LABELS>.

For dynamic labels (generated by macros) I guess you can first preprocess asm source using fasm and get all labels from that?

It would be great if fasm was written in python, with all "macros" as full python code. Literally everything would be possible, and it would probably be much faster, too. Maybe someday...
Post 06 Jun 2013, 21:31
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.

Powered by rwasa.