View previous topic :: View next topic |
Author |
Message |
jallum
Joined: 05 Mar 2008 Posts: 9
|
# of stack levels for 16F877A |
Posted: Fri Aug 15, 2008 11:59 am |
|
|
I've got an unusual result in my statistics output file:
Quote: | ROM used: 2585 (32%)
2982 (36%) including unused fragments
2 Average locations per line
6 Average locations per statement
RAM used: 65 (18%) at main() level
77 (21%) worst case
Stack used: 5 worst case (out of 6 total available)
Lines Stmts % Files
----- ----- --- -----
537 321 76 pc2_ngp.c
71 0 0 pc2_ngp.h
313 0 0 ..\..\..\PROGRA~1\PICC\devices\16F877A.h
224 102 24 ..\pc2.c
----- -----
1145 423 Total |
The PIC 16 should have 8 stack levels! Also according to the call tree, my code only uses 3 stack levels. I understand that I need to budget another stack level for an interrupt, but I can't guess why I would need two additional stack levels...
Is it possible that the compiler stats file decreases the available stack level to show the stack levels available to the user? Does it also increase the number of stack levels I have used to accurately reflect the maximum expected stack usage? It seems it should only do one of these things, not both.
When I first discovered this, the report said 8 stack levels used out of 6 available, and did not generate a warning/error. I have de-nested some functions to reduce the stack usage. I would like to be more than just 1 stack level away from overflow.... can someone confirm that this comment is wrong/flawed, or explain what is happening?
Thanks!
PCW 4.069 |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Aug 16, 2008 12:01 pm |
|
|
I performed some tests:
1) A simple program calling 0 functions and no interrupts
Stack used: 0 worst case (out of 8 total available)
OK
2) A simple test program calling 1 function and no interrupts
Stack used: 1 worst case (out of 8 total available)
OK
3) A simple test program calling 0 functions and 1 interrupt (not calling functions)
Stack used: 1 worst case (out of 7 total available)
Strange.
4) A simple test program calling 0 functions and 1 interrupt (calling 1 function)
Stack used: 2 worst case (out of 6 total available)
Strange.
5) A simple test program calling 0 functions and 1 interrupt (calling 6 nested functions)
Stack used: 7 worst case (out of 1 total available)
Strange; 7 used out of a total of 1 available ???
It seems like the number for 'total available' stack levels indicates the stack levels available to the main program. But the 'worst case' number is the total number of stack levels used by the main program _and_ the interrupts.
Like you said, it looks like the compiler is mixing two strategies where it should only do one. |
|
![](templates/subSilver/images/spacer.gif) |
jallum
Joined: 05 Mar 2008 Posts: 9
|
|
Posted: Mon Aug 18, 2008 10:25 am |
|
|
Thanks, I'm glad someone was able to duplicate what I was seeing.
My interrupt functions do call built in functions, which would explain the need for 2 stack levels by the interrupt functions.
I'll assume that my stats file means either 5 used out of 8, or 3 used out of 6 (depending on how I want to interpret the # of stack levels used). And I'll submit this for a bugfix. |
|
![](templates/subSilver/images/spacer.gif) |
|