1

I want to know what is the Nested Calls Limitations. I am using MikroC for PIC programming.

It says following limitations,

mikroC PRO for PIC limits the number of non-recursive nested calls to:

  • 8 calls for PIC12 family,
  • 8 calls for PIC16 family,
  • 16 calls for PIC16 Enhanced family.
  • 31 calls for PIC18 family.

is It external functions call limitations or If else or loop call limitations? What Nested Calls? How to count in the code to identify whether it is excited or not?

Lundin
  • 155,020
  • 33
  • 213
  • 341
Ind
  • 337
  • 1
  • 6
  • 15

2 Answers2

3

Example for PIC16 without any interrupts:

This code is fine:

/* prototypes */
void func1 (void);
void func2 (void);
void func3 (void);
void func4 (void);
void func5 (void);
void func6 (void);
void func7 (void);
void func8 (void);

void func1(void) {
    /* do something here */
}
void func2(void) {
    /* do something here */
}
void func3(void) {
    /* do something here */
}
void func4(void) {
    /* do something here */
}
void func5(void) {
    /* do something here */
}
void func6(void) {
    /* do something here */
}
void func7(void) {
    /* do something here */
}
void func8(void) {
    /* do something here */
}

int main {
    func1();
    func2();
    func3();
    func4();
    func5();
    func6();
    func7();
    func8();
}

This code is not fine:

/* prototypes */
void func1 (void);
void func2 (void);
void func3 (void);
void func4 (void);
void func5 (void);
void func6 (void);
void func7 (void);
void func8 (void);

  void func1(void) {
    func2();
}
void func2(void) {
    func3();
}
void func3(void) {
    func4();
}
void func4(void) {
    func5();
}
void func5(void) {
    func6();
}
void func6(void) {
    func7();
}
void func7(void) {
    func8();             /* here the stack reached 8. this will cause a problem */
}
void func8(void) {
    /* do something here */
}

int main {
    func1();
} 
Mike
  • 3,513
  • 4
  • 14
  • 31
  • @Scheff Don't be silly. PIC is an embedded system bare metal microcontroller. Where should it `return` to, la-la-land? It is industry standard to use an implementation-defined form of `void main (void)` for all such "freestandarding" systems. This is allowed by the C standard, see [this](https://stackoverflow.com/a/31263079/584518). – Lundin Sep 24 '18 at 09:56
  • Don't listen to some confused PC programmer with the `int main()` dogma. It isn't correct, see comment above. – Lundin Sep 24 '18 at 09:57
  • Yep, this answers the question regardless of petty details about main. – Lundin Sep 24 '18 at 10:01
  • @Ctx Yes, that would be a typo. We can't edit comments. – Lundin Sep 24 '18 at 11:00
  • Interestingly any reasonable compiler will still accept this code and make it work. Simply by inlining the functions. I'm not sure if that MircoC limit relates to the source code or that generated, optimised code (or if it optimises the code like that at all). On a not directly related side note: the code above is not valid C. The functions are called without being declared. – too honest for this site Sep 24 '18 at 11:02
1

The 8-bit PICmcu's have a limited amount of hardware call stack. This stack contains the return address for function calls and interrupts. This stack is NOT a parameter stack for high level languages like C. Because this stack is in hardware it can be made as wide as necessary to provide the entire return address to the CPU in one cycle. It is also impossible for too many function calls to cause the stack to quietly corrupt other memory such as the BSS segment or traditionally, the heap.

For other side effects of a non-traditional stack model. take a look at this article on microforum. secret weapon of the 8-bit PICmcu