Page 2 of 2

2 Beginner questions about assembly programming using CC65

Posted: Sat Feb 06, 2021 7:22 pm
by StephenHorn

I think what's going on is that the ".ifref" is only being considered by the assembler, not the linker, and ".global" doesn't count as a reference. So when you call ca65 with vera.asm, it sees the ".ifref", observes that vera.asm hasn't actually used that procedure anywhere by that point in the file, and then discards it because of your ".ifref". The fix, then, is to remove the ".ifref" and just understand that your clearScreen function will always be included in your lib.

Or, if you wanted to control whether clearScreen is included in a build, you can't do it automatically, you'd have to define and then use .ifdef or plain .if comparisons:


vera.inc:
.define INCLUDE_CLEARSCREEN 1
...
.if INCLUDE_CLEARSCREEN = 1
.global clearScreen
.endif
 
vera.asm
.include "vera.inc"
.if INCLUDE_CLEARSCREEN = 1
.proc clearScreen
...
.endproc
.endif
 
main.asm
.include "vera.inc"
...
jsr clearScreen


Unfortunately, from a quick look it does not appear that cl65 supports any link-time optimization, such as discarding unused segments of code.


2 Beginner questions about assembly programming using CC65

Posted: Sun Feb 07, 2021 11:13 am
by JvH

That's a bummer, but yes I expect that's actually what's happening here.

Did you bother to solve this in your demo, or did you just include your entire graphics library?


2 Beginner questions about assembly programming using CC65

Posted: Sun Feb 07, 2021 3:15 pm
by StephenHorn


3 hours ago, JvH said:




That's a bummer, but yes I expect that's actually what's happening here.



Did you bother to solve this in your demo, or did you just include your entire graphics library?



I simply included my entire graphics library. But I should add that my demo is using effectively the entirety of my graphics library - that's initially why I wrote the lib, after all. Or rather, I did not implement functions in the lib on the basis of theoretical wants, I needed these functions first.


2 Beginner questions about assembly programming using CC65

Posted: Sun Feb 07, 2021 3:28 pm
by desertfish


20 hours ago, StephenHorn said:




it does not appear that cl65 supports any link-time optimization



Heh, no tool is perfect:   I'm using the 64tass assembler, and it does exclude unused blocks/procedures.  However I'm now pondering how to make it not do that because I was thinking about ways to create a library program that includes everything you assemble even though it is not called... ?


2 Beginner questions about assembly programming using CC65

Posted: Sun Feb 07, 2021 3:32 pm
by JvH


1 minute ago, desertfish said:




Heh, no tool is perfect:   I'm using the 64tass assembler, and it does exclude unused blocks/procedures.  However I'm now pondering how to make it not do that because I was thinking about ways to create a library program that includes everything you assemble even though it is not called... ?



In that case I'd highly recommend cc65 ?

I have started a discussion about this on cc65's Github page. Maybe that will lead to some new insights.


2 Beginner questions about assembly programming using CC65

Posted: Sun Feb 07, 2021 7:27 pm
by Elektron72

According to the ld65 documentation, if you are using a library (made using ar65), the linker will only include object files that satisfy imports in your program. If a specific part of a library is never used, it is not included.


2 Beginner questions about assembly programming using CC65

Posted: Tue Feb 09, 2021 5:12 pm
by JvH

Finally, I figured it all out. Thanks guys for your help.

Assembling library method into separate object files and using ar65 to put them into lib files does exactly what I'm aiming for: only assembling the code that I actually use in my main program.

I also realized what I was doing wrong with the .ifref approach. For now I directly include the asm files that make up my main program. I did have a vera.inc file containg my globals (including the clearScreen symbol) and vera.asm that contained the clearScreen method itself.

In my main program though I only included vera.inc, so the clearScreen symbol+implementation couldn't be found.

Another lesson learned ?