#1490 PIC14: STK00 gets overwritten when calling some functions.


Hello. I attach the Makefile I use for the project, just do "make" and "make sim". This is a driver for the T6963 LCD screen. You just need to simulate it to see that something is wrong. I'm using sdcc 2.8.0 on Debian Etch.

When making the simulation, please, put a Breakpoint on line 578: CLRF _TRISB
Then, Run it and when it starts a loop, put two logical ones on input ports B0 and B1, this is to simulate the behaviour of the LCD. Then, when it reaches line 578, see that STK00 is zero, it is correct because if you read at the code variable "carmelomelo" (this strange name is to assure it's different from everything else) is initialized with zero on toggle_led.c:142: dt2(0,0);
But repeat the process two more times, Run and when it stops, Step by and see the output of PORTB. You'll see that the following one is also zero, which is correct, but then, it's one, and it should be 0x40!! (toggle_led.c:143)

I think that the problem is that the compiler uses the same STK00 register for all the parameters that all functions use through the program, and this gets overwritten before using it, because yo do something like:

do nothing but return;

sleep(50000); // Now, STK00 so data is overwritten.
PORTB = data; // Wrong value, not zero.



  • Nestor Amigo Cairo

    Makefile and toggle_led.c test for LCD

  • Nestor Amigo Cairo

    • assigned_to: nobody --> tecodev
  • Raphael Neider

    Raphael Neider - 2008-11-27

    The problem is your calling sdcc with the --stack-auto argument, which is not supported by the pic14 port. The --stack-auto switch causes the arguments to a function to be reversed in SDCCast.c (decorateType), l. 4747, which is not compensated/honored in the pic14 backend.
    Just leave out the --stack-auto switch and you should be fine.
    Working around another compiler bug (that also causes registers to be reused incorrectly), you might want to add --nooverlay instead. This disables an optimization and thus increases the memory footprint, but the resulting code should be more likely to work properly.

    Good luck,

  • Raphael Neider

    Raphael Neider - 2008-11-27
    • milestone: --> known_bugs
    • status: open --> open-later
  • Nestor Amigo Cairo

    Thank you. I have tried with latest CVS version, and it works flawlessly with --no-overlay. The old "stable" version is not very good at this task. I'm going to comment any further incidence, I'm very interested in the port to PIC14.

  • Maarten Brock

    Maarten Brock - 2011-09-18
    • summary: STK00 gets overwritten when calling some functions. --> PIC14: STK00 gets overwritten when calling some functions.
  • Philipp Klaus Krause

    • Category: --> PIC14

Log in to post a comment.

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

Sign up for the SourceForge newsletter:

No, thanks