In the sdas documentation (sdcc-src-4.1.0/sdas/doc/asmlnk.txt), the directives .ifdef and .ifndef are mentioned, but it seems that they're not implemented. I couldn't find any evidence of them in the source code (other than a commented-out line in asstm8/stm8pst.c), and when I tried to use .ifdef with sdaspdk14, I got an error message.
Code example (test.asm):
PB = 0x14
.ifdef PB
mov PB, a
.endif
Assembler output:
$ sdaspdk14 -lop test.asm
test.asm:2: Error: <o> .org in REL area or directive / mnemonic error
test.asm:4: Error: <i> .include file error or an .if/.endif mismatch
removing test.rel
There is an incosistency between the assembler documentation and what the assembler implements. I think this is due to the planned sdas merge with asxxxx 5.0 never being completed.
Is there a work around for this - another way to check if a symbol is defined, or not? For example, whether a SFR exists (a global symbol defined in another module)?
I'd like to set an SFR but only if the symbol exists (I have two targets where the same address is used for two different SFRs. I tried .ifdef but have the same error as described.
You can use external preprocessing tools.
I'm not 100% sure whether you can simply use the C preprocessor, though.
There must not be any collisions between preprocessor syntax and assembler syntax, obviously.
We are now a little out of the scope of this ticket, but I just tried that and preprocessor can be used
sdcpp -P kernel.a51 -o kernel.asmbut it struggles with assembly code comments. It only gave me warnings, but I see potential for unexpected effects with some comments that could catch the unwary.
(The -P is needed so sdcpp does spit # xxx lines in to the output)
Last edit: Steven Borley 2022-02-20
Even if
.ifdefwas implemented, that wouldn’t work.PBis not defined with.define(also not supported)As far as I understand is
.ifbthe equivalent for direct assignments (=/.equ), but we neither have that ^^'You can check if PB≠0
.if PBor check if it’s equal to a specific number.if eq PB 0x14, but there has to be a direct assignment for this to work.In trunk we only have those comparators:
.if ne,.if eq,.if gt,if lt,if ge,.if le(+ the short versions.ifneetc)There is also
.if f,.if tand.if tf, but they have different functions..if def,.if ndefand.defineare innext/branch, so they should get merged back and be available in snapshots after 4.2.0 was released. Though there is still no.if b. And for now they are only enabled for as6500. I’m hesitant to enable them for all as long as there are no continuous regression tests running, but should be fine doing that once it’s merged back.I was wrong about
.ifb, it’s for macros not for direct assignment.SDCC now supports all kinds of
.ifdirectives from ASxxxx.I want to reformat the definition files when I enable them for all assemblers, so I’m currently waiting for feedback from upstream in that regard.
Should work with [r13215].
I skipped the reformating.
Related
Commit: [r13215]