Jump to content

Photo

atasm macro forward reference to label

6502 assembly atasm

3 replies to this topic

#1 kenjennings OFFLINE  

kenjennings

    Dragonstomper

  • 789 posts
  • Me + sio2pc-usb + 70 old floppies
  • Location:Florida, USA

Posted Wed Mar 21, 2018 8:42 AM

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, Wed Mar 21, 2018 11:18 AM.


#2 JAC! OFFLINE  

JAC!

    Stargunner

  • 1,760 posts
  • Always looking for GFX and MSX for my demos
  • Location:Lebach, Germany

Posted Wed Mar 21, 2018 1:15 PM

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.co...oMADSConversion

 

Regards, Peter.



#3 kenjennings OFFLINE  

kenjennings

    Dragonstomper

  • Topic Starter
  • 789 posts
  • Me + sio2pc-usb + 70 old floppies
  • Location:Florida, USA

Posted Wed Mar 21, 2018 5:09 PM

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.



#4 kenjennings OFFLINE  

kenjennings

    Dragonstomper

  • Topic Starter
  • 789 posts
  • Me + sio2pc-usb + 70 old floppies
  • Location:Florida, USA

Posted Wed Mar 21, 2018 8:37 PM

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...

M65SimpleForwardRefPrg.png

 

 

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

 

M65SimpleForwardRefAsm.png

 

 

And, the macro version...

 

M65MacroForwardRefPrg.png

 

 

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

 

M65MacroForwardRefAsm.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.

 

M65NoMacroForwardRefAsm.png

 

 

 







Also tagged with one or more of these keywords: 6502, assembly, atasm

0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users