Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Doubt on "STACK"...

Status
Not open for further replies.

Joyhtidas

Member level 4
Joined
Nov 30, 2009
Messages
72
Helped
4
Reputation
8
Reaction score
1
Trophy points
1,288
Location
Bangalore, India
Activity points
1,709
Hi...
I am developing a appication in which the user can choose many 'operation modes'
... So to jump from one mode to another i used the 'switch' case statements...
Below shows the code structure... My doubt is that, whether the stack will overflow
when i write a code like this....

[

Thanks..
 
Last edited:

Depends which chip you're using. A PIC16 usually has an 8 level deep stack, so you could do up to 6 function calls one inside the other. The reason I say 6 instead of 8 is because you should always try to leave room for an occasional interrupt since that uses the stack as well.

Higher model chips, such as a PIC18 has a 31 level deep stack, so you have a lot more headroom to work with.
 

The answer depends entirely on the kind of processor you are using and how it implements the stack. If it is a processor with an accessible stack pointer, you can probably push hundreds of bytes on to it without any problem, if it's a small PIC for example, you might only have an 8 byte deep stack. It also depends upon the number of functions/subroutines you call elsewhere in the program and in the switch statements.
Brian.
 

Hi....
I am using the PIC24F series processor.... So i hope there won't be much problems with the stack....
As i explainied in the picture, i have many operation modes.... the user can choose from one to another
at any time... so how should i write the algorithm...?
 

Remember that with every "return" the PC is popped OUT of the stack as well. It's only if you call a function within a function 32 times.

In other words:

F1 calls F2, F2 calls F3, F3 calls F4, F4 calls F5....and so on... it'll run out of stack space quickly :)

If you have:

F1 calls F2 which calls F3, F4, F5 and so on Sequentially, it's only going to use 2 levels of stack.
 
Hi,
But in application... 5 different operation modes are there from main menu itself....
And the main menu is always accesible to the user.... Do u have any idea for this problem..?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top