Menu

#2922 PDK compiler / assembler error when defining a label in inline assembler when used inside of a for loop

open
nobody
None
PDK
3
2019-12-09
2019-07-02
Free-PDK
No

A label defined in inline assembler (e.g. used ofr a tight busy loop) compiler / assembler will give an error if the inline aseembler block is inside of a for loop:

void main(void)
{
  for(;;)
  {
    __asm
      mov a,#7
    asmloop:  
      dzsn a
      goto asmloop
    __endasm;
  }
}

Output: build/testasmloop.asm:108: Error: undefined symbol encountered during assembly

When looking at the compiler created assembler file it looks fine (except the indentation of the label):

_main:
00102$:
; testasmloop.c: 16: __endasm;
  mov a,#7
        asmloop:
  dzsn  a
  goto  asmloop
  goto 00102$
00104$:
; testasmloop.c: 18: }
  ret

Discussion

  • Free-PDK

    Free-PDK - 2019-08-16

    I researched a bit more and found that the problem is caused by the assembler.

    The problem is caused by mixing numeric labels ( e.g. 00102$: ) with normal labels ( e.g. label: ).

    The following short assembler program shows the error:

    testbad.asm:

        .area HEADER (ABS)
    00102$:
    label:
        goto  00102$
    

    ./sdaspdk13 test.asm
    test.asm:4: Error: < u > undefined symbol encountered during assembly
    removing test.rel

    This version works fine:
    testok.asm:

        .area HEADER (ABS)
    00102$:
    01234$:
        goto  00102$
    
     
  • Free-PDK

    Free-PDK - 2019-09-07

    According to an old copy of SDCC user guide (e.g. from here: http://fivedots.coe.psu.ac.th/~cj/masd/resources/sdcc-doc/SDCCUdoc-13.html) it is not allowed to use normal labels in inline assembler (this matches exact the observed behaviour):

    ***All labels defined within inline assembler code HAS TO BE of the form nnnnn$ where nnnn is a number less than 100 (which implies a limit of utmost 100 inline assembler labels per function).


    In contrast the current SDCC user guide (http://sdcc.sourceforge.net/doc/sdccman.pdf) does not mention this fact and also gives a BAD example (chapter 3.11):

    old format:
    Example

    __asm
      ; This is a comment
      label:
         nop
    __endasm;
    

    new format:
    Example:

    __asm__ (; This is a comment\nlabel:\n\tnop);
    
     
  • Maarten Brock

    Maarten Brock - 2019-11-09
    • Priority: 5 --> 3
     
  • Maarten Brock

    Maarten Brock - 2019-11-09

    You're right that the example is bad.

    But the old explanation is still there in 3.11.4 Use of Labels within Inline Assembler

     
  • Maarten Brock

    Maarten Brock - 2019-11-09
     
  • Maarten Brock

    Maarten Brock - 2019-11-09

    Please do not assign bugs to developers. It is up to the developers to pick something up and assign it to themselves.

     
  • Erik Petrich

    Erik Petrich - 2019-12-09
    • assigned_to: Philipp Klaus Krause --> nobody
     

Log in to post a comment.

MongoDB Logo MongoDB