#1469 compiler improperly reuses registers - pic14

closed-fixed
nobody
5
2013-05-25
2008-07-21
Keith
No

Using the command:
sdcc -mpic14 -p16f628a test.c
to compile the attached file test.c, with sdcc version 2.8.1, the compiler improperly reuses registers.

For example, look at the assembly file, and notice that the function sendStringSerial(unsigned char *) calls both the function delay(unsigned char) and the function sendByteSerial(unsigned char).

In my assembly file delay(unsigned char) and sendByteSerial(unsigned char) both use r0x102D and r0x102E. This messes things up for sendStringSerial(unsigned char *) because sendStringSerial(unsigned char *) uses r0x102D and r0x102E to hold part of the pointer from its parameter.

Note that if I modify sendStringSerial(unsigned char *) so that it is completely self-contained, it sends strings as it should, but if sendStringSerial(unsigned char *) calls other functions to simplify its work, the compiler messes up.

If I can attach more files, I'll include my assembly file, and a version with a self-contained sendStringSerial(unsigned char *).

Discussion

  • Keith

    Keith - 2008-07-21
    • summary: compiler improperly reuses registers --> compiler improperly reuses registers - pic14
     
  • Keith

    Keith - 2008-07-21

    Logged In: YES
    user_id=1112645
    Originator: YES

    File Added: test.asm

     
  • Keith

    Keith - 2008-07-21

    sdcc improperly reuses registers with this

     
  • Keith

    Keith - 2008-07-21

    Logged In: YES
    user_id=1112645
    Originator: YES

    File Added: test.c

     
  • Keith

    Keith - 2008-07-21

    Logged In: YES
    user_id=1112645
    Originator: YES

    File Added: test.asm

     
  • Keith

    Keith - 2008-07-21

    asm file generated by sdcc for test.c

     
  • Keith

    Keith - 2008-07-21

    Logged In: YES
    user_id=1112645
    Originator: YES

    File Added: selfContained.c

     
  • Keith

    Keith - 2008-07-21

    it works if the sendStringSerial(unsigned char *) function is self-contained

     
  • Raphael Neider

    Raphael Neider - 2008-08-10
    • assigned_to: nobody --> tecodev
     
  • Raphael Neider

    Raphael Neider - 2008-08-10

    Logged In: YES
    user_id=1115835
    Originator: NO

    As a workaround, SDCC r5209 adds the --no-overlay option to the pic14 target to prevent the compiler from overlaying registers used for local variables in different functions. This heavily increases RAM usage but avoids this bug.

    This bug might be the cause of "[Sdcc-user] pic14 16f628a sdcc 3.8.0 never ending loop - mis-compilation?" and should be fixed properly soon...

    Thank you for the analysis!

     
  • Raphael Neider

    Raphael Neider - 2009-02-28

    Fixed with patch from #2512926 in SDCC 2.8.9, r5394.
    Now, calling this "soon" would be rather bold, but, well, it got fixed finally...

     
  • Raphael Neider

    Raphael Neider - 2009-02-28
    • milestone: --> fixed
    • assigned_to: tecodev --> nobody
    • status: open --> closed-fixed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks