Menu

#3302 .ifdef and .ifndef directives missing

open
nobody
None
sdas
5
2022-03-13
2022-01-08
No

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

Discussion

  • Philipp Klaus Krause

    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.

     
  • Steven Borley

    Steven Borley - 2022-02-20

    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.

     
    • Benedikt Freisen

      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.

       
      • Steven Borley

        Steven Borley - 2022-02-20

        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.asm
        but 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
  • Sebastian Riedel

    Even if .ifdef was implemented, that wouldn’t work. PB is not defined with .define (also not supported)

    As far as I understand is .ifb the equivalent for direct assignments (=/.equ), but we neither have that ^^'

    You can check if PB≠0 .if PB or 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 .ifne etc)

    There is also .if f, .if t and .if tf, but they have different functions.

    .if def, .if ndef and .define are in next/ 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.

     
    • Sebastian Riedel

      I was wrong about .ifb, it’s for macros not for direct assignment.
      SDCC now supports all kinds of .if directives 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.

       
      • Sebastian Riedel

        Should work with [r13215].
        I skipped the reformating.

         

        Related

        Commit: [r13215]


Log in to post a comment.

MongoDB Logo MongoDB