Home > OS >  How to access assembly language symbols without a leading _ from C on 6502 (cc65)
How to access assembly language symbols without a leading _ from C on 6502 (cc65)

Time:02-27

I'm writing some code in 6502 assembly language using cc65.

Because I'm living in 2022 and not 1979 and have access to a development machine that is a million times more powerful than the target platform, I'm writing unit tests for the assembly language code in C.

Obviously the calling conventions for C and assembly language are different, so I have a bunch of wrapper functions that accept C-style arguments and then call the assembly language functions.

But after calling an assembly language function, I want to check the state of various globals that are defined in assembly language, but I can't because C expects all identifiers to start with an underscore '_' and the identifiers in my assembly language modules don't.

I could just export every symbol twice, once with a '_' prefix and once without, but it seems so clunky and I just wonder if there's an easier way? Is there a #pragma or something that I can use to tell C to use the symbol name exactly as-is, without adding an underscore?

I've looked in the cc65 docs and found nothing, but it seems like a pretty common need, and I'm wondering what other people do.

CodePudding user response:

It is likely that the cc65 compiler only supports access to symbols with the ABI-specificed decoration, i.e. those beginning in an underscore _.

To access other symbols, they therefore must either be renamed to follow the decoration or a decorated alias must be created.

_foo    EQU foo

For functions, it is also worth considering to write wrapper functions. This may improve the ability to debug the code as debuggers tend to get confused when two symbols refer to the same address.

  • Related