CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Stack overrun concerns!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Tom-H-PIC



Joined: 08 Sep 2003
Posts: 105
Location: New Castle, DE

View user's profile Send private message

Stack overrun concerns!
PostPosted: Wed Apr 07, 2010 6:17 am     Reply with quote

Hello All
I'm work on a project that started years back and has had a number of version of firmware released.
The compiler is 3.249, PIC16F916.
Would someone explain how the compiler handles the stack and what can be done to reduce it?
The 16F916 data sheet states that the 916 has an 8-level deep hardware stack.
The program that I have now works as it was designed.
But my concern is in look at the list file I see this.
" Stack: 7 worst case (6 in main + 1 for interrupts)"
Do I need to be concerned about this?
How do I reduce the stack load?
Tom
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Wed Apr 07, 2010 7:19 am     Reply with quote

No problem.
The compiler calculates the 'worst case', by looking at where things are/can be called inside other things. So in your case, the 'worst case', is if an interrupt happens, when you are inside a subroutine, inside another, etc.. 6 deep in the 'main code', then another one for the interrupt. Nothing to worry about at all. Remember in the PIC, the stack is only used for call/return operations, not for data storage, so there is nothing 'extra' that can happen, and go beyond it's limits. Where it _would_ be a 'worry', would be if your code wanted 9 deep....
You can reduce stack usage, by making routines 'inline', but this then reduces the ability to split the code up, and fit it efficiently in the memory banks, and increases the risk of 'out of memory' errors. So long as you are inside the limits, don't worry.

Best Wishes
Tom-H-PIC



Joined: 08 Sep 2003
Posts: 105
Location: New Castle, DE

View user's profile Send private message

Stack overrun concerns!
PostPosted: Wed Apr 07, 2010 1:09 pm     Reply with quote

Thanks Ttelmah
That is what I thought and had been working under for years.
Then I got to thinking about it and did not have any references to back that up.
And this morning was not able find anything on the web after about an hour.
So thanks for your knowledge. Tom
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group