The Call Stack debugger window was designed for the inclusion of recursion in ROBOTC. It tracks the order, or 'stack' of which functions are 'called' in a LIFO (Last In First Out) system.

 

An example of this (shown below) is three functions being called in a program; task main calls FunctionOne, FunctionOne calls FunctionTwo, and FunctionTwo calls FunctionThree (Last In). FunctionThree then calls itself multiple times in a process known as "recursion" (for more information, see Memory Overload).When FunctionThree has completed its loop it exits (First Out) back to wherever it was called from (in this case, FunctionTwo) and program flow continues.

 

Watch the Call Stack as the yellow line tracks the steps the program goes through. (Note that we skip over a few steps for the sake of brevity)

 

1) The program begins by initializing Task Main

 

 

2) Then the program calls FunctionOne, thus initializing it in the call stack

 

 

3) FunctionOne calls FunctionTwo, which is then also initialized.

 

 

4) FunctionTwo calls FunctionThree, which is initialized as well.

 

 

5) FunctionThree calls itself once (recursion), then because of the counting variable in the if else statement, hits a return statement, which causes the last initialized function (the second instance of FunctionThree) to exit.

 

 

6) FunctionThree hits a second return, which eliminates the original instance of FunctionThree. This then causes the program to jump back into FunctionTwo (since FunctionThree finished executing).FunctionTwo comes then to its curly brace, which signifies its end.

 

 

7) Finally, the program jumps back to FunctionOne, which had called FunctionTwo, coming then to another curly brace and jumping back to task main, which then at last comes to its own curly brace, which ends the program.

 

 

As shown above, the Call Stack debugger window tracks each function as it's called (starting with Task Main at address x00) and 'stacks' each function calling on top of the one that called it. The PC line shows where the program is currently running at, and as functions end the Call Stack will shrink to reflect the removal of those functions from the stack.