Jump to content
IGNORED

atasm macro forward reference to label


Recommended Posts

I was trying to do something that my feeble memory thought worked 30 years ago in Mac/65 and not getting any joy in atasm.

 

I'm making macros to act as wrappers to function calls in a library of routines. Then I'm conditionally assembling routines in the library, so if they are not referenced, they don't get included and waste space. I was figuring this would work.... (only important parts included)

.macro mFunc
    ; other stuff happens
    jsr libFunc
.endm

; Later in the main code....

    mFunc

; Later....

.if .ref libFunc
libFunc
    ; fun stuff ensues
    rts
.endif

This does not work. The .ref does not see the libFunc referenced, so it does not build libFunc. Should this work? Or am I insane?

 

If the forward referenced label doesn't work, how about a declared value in the macro like this?...

.macro mFunc
    DO_FUNC .= 1
    ; other stuff happens
    jsr libFunc
.endm

; Later in the main code....

    mFunc

; Later....

.if .ref DO_FUNC ; and .def does not work either.
libFunc
    ; fun stuff ensues
    rts
.endif

DO_FUNC set in the macro is also not seen. neither .ref or .def sees it.

 

 

Next fallback plan...

DO_FUNC .= 0

; Later on....

.macro mFunc
    DO_FUNC .= 1
    ; other stuff happens
    jsr libFunc
.endm

; Later in the main code....

    mFunc

; Later....

.if DO_FUNC>0 
libFunc
    ; fun stuff ensues
    rts
.endif

This (annoyingly) does work. DO_FUNC defined outside the scope of a macro can have its value changed in a macro, and THAT value change is seen by the conditional assembly.

 

Rather not have to throw in a bunch of flags in a header file separate from the library file which is included in the end of the assembly.

Edited by kenjennings
Link to comment
Share on other sites

Hi Ken,

 

I don't think you can get this to work with the way the parser in ATASM works.

Leaving unreferenced code out is normally done by the linker, not by the parser.

That is because you have to know when the last pass is over before you can decide what is really unused.

My recommendation would be to switch to MADS and use .PROC./ENDP and the option "-x Exclude unreferenced procedures".
Since MADS also also 99% MAC/65-alike only few minor things have to be adapted. Here's how:

https://www.wudsn.com/index.php/ide/faq#FAQATASMtoMADSConversion

 

Regards, Peter.

  • Like 2
Link to comment
Share on other sites

Actually I found that its not specific to macros. Any forward reference does not count as a reference for conditional assembly.

MAIN
    jsr FUNC1
    jmp MAIN

.IF .REF FUNC1
FUNC1
    ; something
    rts
.ENDIF

This fails to find FUNC1. Shouldn't it keep a placeholder for "memory address FUNC1 referenced" in pass 1, and then pass 2 fills in the address? It makes me wonder what .def and .ref can do.

Link to comment
Share on other sites

Mac/65 says I am not insane. The 30 years added to the brain cells have not yet turned them to mush.

 

 

This is the simple program version...

post-32235-0-28699700-1521685747.png

 

 

ASM shows the forward reference is recognized by the .REF during assembly...

 

post-32235-0-04604100-1521685708.png

 

 

And, the macro version...

 

post-32235-0-69702400-1521685616.png

 

 

And it works too. The forward ref from macro invocation is recognized by .REF...

 

post-32235-0-17659800-1521685865.png

 

 

Just to be sure Mac/65's doesn't assume the macro declaration itself causes the .REF, this is assembly with MFUNC commented out in MAIN. It does not see the reference to FUNC and so does not assemble that code.

 

post-32235-0-12792000-1521686177.png

 

 

 

  • Like 3
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...