Page 1 of 1

Macros - How Many levels deep can your go?

Posted: Sat May 19, 2007 5:15 pm
by Ron
Hi,

I am writing my first macros and I was wondering what the limits are regarding macros calling other macros.

In my case everything is completely linear.

My main flowchart calls MACRO 1.

MACRO 1 will call one of 4 other "MACROS XX" based on a parameter tested by MACRO 1.

MACROS XX will call one of two possible MACROS YY.

Then MACROS YY will complete, return to MACRO XX which will complete, and then return to MACRO 1 which will complete and return to the main flowchart.

This is a pure tree structure, there are no "stars" at any point.

Am I to deep with macros calling other macros?

What are the limits?

Thanks

Ron

Posted: Mon May 21, 2007 9:24 am
by Benj
Hello Ron

The absolute maximum subroutine levels in a PICmicro is 8. However it is always good practise to leave at least two of these levels free incase an interrupt or something similar occurs. If a interrupt did occur that went over the 8 levels of return adress stack then the PICmicro would become lost and may start to execute code in a random manner.

Posted: Mon May 21, 2007 10:22 am
by Steve
Although there are only 8 levels of stack in the PICmicro's hardware, the underlying C compiler is a bit more clever and can be set to use a software stack. So in theory, you should be able to use a lot more macro calls than 8.

Look at the "BoostC.pdf" help file - search for "stack" or "-swcs" for more information.