What are the nesting limits of function calls on 8-bit PIC® devices?

For PIC18 devices, the function call depth is the same as the depth of the hardware return address stack.
Check the datasheet for the device you are using.

Baseline PIC® devices have a very small hardware stack depth (2 calls) and to work around this, the compiler can employ a call mechanism based on lookup tables. This allows a much larger level of function nesting, with no theoretical limit. Use of the alternate call mechanism is automatic.

You must ensure that the maximum hardware stack depth is not exceeded; otherwise, the code may fail functionally. Nesting function calls too deeply will overflow the stack. It is important to take into account implicitly called library functions and interrupts, which also use levels of the stack. The compiler can be made to manage stack usage, for non-PIC18 devices, by using the “stackcall” suboption supplied to the “—RUNTIME” compiler option.

The call graph produced by the code generator in the assembler list file will indicate the stack levels at each function call and can be used as a guide to stack depth. The code generator will also produce warnings if the maximum stack depth is exceeded.

See your MPLAB® XC8 compiler manual for more information on function calls.

© 2016 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.