I would like to convert an assembler program in ca65 with macros into assembler code with resolved macros in order to carry out manual or automatic optimizations with the resulting code. Then, the assembler program should be assembled into object code/executable code.

Is there an option or macro for ca65 to make it run only the macro pre-processor?

I'm assembling with

ca65 myprog.s
cl65 myprog.o -C c64-asm.cfg -u __EXEHDR__ -o myprog.prg

or using cl65 in one step

cl65 myprog.s -C c64-asm.cfg -u __EXEHDR__ -o myprog.prg

Mini example for myprog.s with macros:

loop:   inc $D021
        .repeat 20
        jmp loop
  • 1
    AFAIK CA65 does not provide an intermediate, macro resolved, form. Does simply parsing the listing not satisfy your need? Maybe with a high number of listed bytes per line? – Raffzahn Dec 13 '20 at 0:47
  • Thanks for the suggestion. Simply parsing would work for .repeat, but I also might have recursive macros and usage of .if, .ident', ̀set, etc. Parsing this would mean a reimplementation of the macro processor. – Peter B. Dec 13 '20 at 0:53
  • 1
    Erm, no, I thought about parsing the listing produced, not the source code. – Raffzahn Dec 13 '20 at 0:59
  • I generated the listing with ca65 --listing myprog-lst.txt myprog.s but the listing does not expand the macros to source code either. It shows the program bytes, but on the right just the macro name. It does not add labels generated by the macro for example, a BNE appears just as 06 in the text. Decoding the program bytes would be thus the same as running a disassembler over the generated binary, which is risky since the disassembler could potentially oversee a jump label or misinterpret code. In contrast, the assembler, getting the code from the macro'd sourcecode has this information. – Peter B. Dec 13 '20 at 1:23
  • 1
    True, still, it would be better than running a disassembler, as the interpretative part is only needed for macros. So results depend a lot on the amount and complexity of macros. But yeah, CA65 is, lets say unusual, as assembler. (P.S.: number of bytes listed can be handeled with --list-bytes) – Raffzahn Dec 13 '20 at 1:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.