Jump to content
IGNORED

Generating global labels in a macro ?


Windless

Recommended Posts

hi,

 

  I am generating some code with a macro, and I would like this macro to generated global unique labels. e.g., when called twice, the macro would output :

MyMacroLabel1_1
	lda	#$00
MyMacroLabel2_1
	ldx	#$00
MyMacroLabel3_1
	ldy	#$00

MyMacroLabel1_2
	lda	#$00
MyMacroLabel2_2
	ldx	#$00
MyMacroLabel3_2
	ldy	#$00

Is it possible to do so with DASM ? I thought I would use something like :

IFNCONST CallIndex
CallIndex	set	0
ELSE
CallIndex	set CallIndex + 1
ENDIF

["MyMacroLabel1_" + CallIndex]
	lda	#$00

But after one hour of trying, I didn't manage to have this working.

Link to comment
Share on other sites

I've tried many ways to do this, too. No luck.

My approach was to try passing constructs to macros and hope they were evaulated instead of used verbatim. No luck.

There appears to be no way to generate a label based on a "variable" containing the text for that label.

I hope to be proven wrong - but this one has me stumped.

 

Link to comment
Share on other sites

Thanks.


For now, since each call to my macro will generate the same "local global" labels, I did like this :

        MAC     GENCODE
.genStart SET .               
                nop
                nop

_label1 SET . - .genStart                
                lda             #1
                nop

_label2 SET . - .genStart               
                lda             #2
                nop
 
        ENDM


then I use the relative labels this way :
 

generated1
        GENCODE
 
generated2
        GENCODE

        jmp     generated1 + _label1
        jmp     generated1 + _label2
        jmp     generated2 + _label1
        jmp     generated2 + _label2


This works because relative labels have the same value each time in my macro. Else I would need to use absolute values and capture each one :
 

       GENCODE
label1_1        set _label1
label2_1        set _label2

        GENCODE
label1_2        set _label1
label2_2        set _label2


But that still doesn't allow for a varying number of generated labels.

Edited by Windless
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...