If you use in-line assembly language within a SDCC program, are you limited to the types of labels you may use if the assembler code branches?
As an example, the following "do-nothing" program compiles and assembles just fine:
void main(void) { _asm nop nop nop _endasm; }
The following program, with an assembler label and a jump instruction, also compiles and assembles without error:
void main(void) { _asm nop alabel: nop ljmp alabel nop _endasm; }
But this code, although it compiles just fine, generates an "undefined symbol encountered during assembly" error:
void main(void) { char i; if (i == 1) { _asm nop alabel: nop ljmp alabel nop _endasm; } }
The problem is that SDCC generates the ".asm" file with labels of the form "0xxxx$:", where xxxx is some number. The "alabel" label creates a barrier between code above it and code below it. The IF statement generates code above "alabel" which references the compiler-generated label below "alabel", and cannot find it.
If you change the program to use a label of the form "0xxxx$" it compiles and assembles fine again:
void main(void) { char i; if (i == 1) { _asm nop 01000$: nop ljmp 01000$ nop _endasm; } }
Is there a way around this problem? Interestingly enough, the SDCC manual shows an example of in-line assembler with a "normal" label.