2 Beginner questions about assembly programming using CC65

Chat about anything CX16 related that doesn't fit elsewhere
User avatar
StephenHorn
Posts: 565
Joined: Tue Apr 28, 2020 12:00 am
Contact:

2 Beginner questions about assembly programming using CC65

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

Developer for Box16, the other X16 emulator. (Box16 on GitHub)
I also accept pull requests for x16emu, the official X16 emulator. (x16-emulator on GitHub)
JvH
Posts: 10
Joined: Wed Feb 03, 2021 6:19 pm

2 Beginner questions about assembly programming using CC65

Post 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?

User avatar
StephenHorn
Posts: 565
Joined: Tue Apr 28, 2020 12:00 am
Contact:

2 Beginner questions about assembly programming using CC65

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

Developer for Box16, the other X16 emulator. (Box16 on GitHub)
I also accept pull requests for x16emu, the official X16 emulator. (x16-emulator on GitHub)
User avatar
desertfish
Posts: 1123
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

2 Beginner questions about assembly programming using CC65

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

JvH
Posts: 10
Joined: Wed Feb 03, 2021 6:19 pm

2 Beginner questions about assembly programming using CC65

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

Elektron72
Posts: 137
Joined: Tue Jun 30, 2020 3:47 pm

2 Beginner questions about assembly programming using CC65

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

JvH
Posts: 10
Joined: Wed Feb 03, 2021 6:19 pm

2 Beginner questions about assembly programming using CC65

Post 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 ?

Post Reply