Dubious loops in SDCC

  • robert

    robert - 2008-11-25

    I have a rather small SDCC project on MCS51 - I use  while(1) for an infinite main.  Oddly though, it loops a few times and then marches on to the next code it finds.  The disassembly seems fine - so it must be some kind of crazy stack thing that I haven't been able to track down.  Even when I wrap a goto around the while - it doesn't help.  I have tried --main-return both and and off without any effect.

    Finally, it looks like I fixed it with a for/next with an embedded goto.  It seems to an effective infinite then, but has anyone else seen this of have some suggestions or am I just a little crazy?

    The main thing I want is some stable behavior that can be rationally explained so I can trust this compiler.

    • Maarten Brock

      Maarten Brock - 2008-11-25

      Unless you see this behaviour in a simulator, I think you should distrust your hardware. Do you have a stable Vcc? No watchdog intervening? Is the oscillator frequency correct?

      But if you really think you found a bug in the compiler, file a bug report with the C and generated asm attached.

    • robert

      robert - 2008-11-25

      Haha - how ironic, my customers always have bad bad bad hardware!

      However, in this case, the design has been working fine with Keil C51 for a few months now, I do not have interrupts going, and the behavior is consistent :-/  I will try a different board though.  Also - good idea - I will try it on some simulator and try to get more detail esp if no one else has seen this same behavior.


    • robert

      robert - 2008-11-26

      OK - this may have been causing the issue, but if not it is a definite problem by itself, SDCC is thrashing the stack.  Is it some setting I have missed or do I have to manage this 100% on my own?  From the users manual - I got the impression that the startup code would automatically take care of such things (as the SP=07).

      Source Code:

      struct LCD_STRUCT {
          char Buffer[50];

      data struct LCD_STRUCT Lcd;

      Map file:

      Area                               Addr   Size   Decimal Bytes (Attributes)
      --------------------------------   ----   ----   ------- ----- ------------
      DSEG                               0000   0032 =     50. bytes (REL,CON)

            Value  Global
         --------  --------------------------------
           0008    G$Lcd$0$0
           0008    _Lcd

    • robert

      robert - 2008-11-27

      I root caused it to the stack problem. A call inside the loop went awry and the bad return looked at first like the while() was errant.


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

Sign up for the SourceForge newsletter:

No, thanks