I've been messing with PICs for a while, but I can't say that I ever really gained a grasp of what stack depth meant.
Say I have a PIC with a 16 deep call stack. What does this mean in practice?
It seems like I have made a call that in turn makes more that 16 calls without a problem. Can I make a call from my main code, and then make more than 16 other calls, as long as I don't branch more than 16 times from the ORIGINALLY called routine?
You can only have a maximum of 16 entries in total on the stack, each call uses one entry - you need to consider interrupts as well (as these use the stack), which is why it's bad practice to use calls from within interrupts.
If your first call makes 16 further calls, then that's exceeded the stack, and it WILL crash, probably messily.
Bear in mind the 16 calls must be nested to cause a problem, any call which has returned clears it's space on the stack.
Alirght, so with this..... how many levels are used on is the "Call ALLLEDON" command?
I'm thinking 1 for the call itself, and then even though the "CALL EVENLEDON" command makes three more calls, I've just used a total of two levels for the "CALL ALLLEDON" command.
How many more calls from the "EVENLEDON" call would I have had to of made to have caused the stack to overflow?
I'm no expert as I'm learning PICs myself, but as I understand it the stack is a circular buffer used to store the program counter contents during the calling of a subroutine as well as interrupts. It is LIFO...meaning Last In First Out...meaning that the last program counter that was PUSHED onto the stack upon a "CALL" or an interrupt is the first one that gets "POPPED" off of the stack when a return instruction is executed.
The main thing is that when dealing with nested subroutines (i.e. calling subroutines within a subroutine) you need to consider stack space to prevent stack overflow. When you have say an 8 level stack...you can PUSH the stack 8 times without a call to POP the stack (i.e. the execution of a return instruction) before the stack if full. If a 9th PUSH occurs prior to the 8th PUSH being POPPED off the stack (i.e. either from an interrupt or a 9th call isntruction), stack overflow occurs and the first Program Counter data that PUSHED the stack gets pushed out. Not sure about the other PICs but I know with the mid range PICs there is no "stack overflow error" bit that gets set when this happens...it just simply pushes the first push out from under the stack.
When this happens, once you execute all of your return instructions to pop the stack, it won't know where to go when the return from the first push is called and essentially you end up with a rogue program.
Alirght, so with this..... how many levels are used on is the "Call ALLLEDON" command?
I'm thinking 1 for the call itself, and then even though the "CALL EVENLEDON" command makes three more calls, I've just used a total of two levels for the "CALL ALLLEDON" command.
How many more calls from the "EVENLEDON" call would I have had to of made to have caused the stack to overflow?
Isn't that a fuse option on 18F' devices, where you can either reset the device after a stack overflow or just rollover the stack pointer after a stack overflow?
Isn't that a fuse option on 18F' devices, where you can either reset the device after a stack overflow or just rollover the stack pointer after a stack overflow?