Keil Logo

The Call Tree

The best way to demonstrate how the call tree is generates is with an example. Based on the following program flowchart, the startup code calls the main C function which subsequently calls func_a, func_b, and func_c sequentially. The functions call no other routines in our program.

Call Tree Example

The arguments and local variables of func_a, func_b, and func_c meet the rules listed in the Theory of Operation and, therefore, may be overlaid. The source code for this flowchart is as follows:

char func_a (char arg1, char arg2, char arg3)
return (arg1+arg2+arg3);

int func_b (int arg1, int arg2, int arg3)
return (arg1+arg2+arg3);

long func_c (long arg1, long arg2, long arg3)
return (arg1+arg2+arg3);

void main (void)
char var_a;
int  var_b;
long var_c;

var_a = func_a(1,2,3);
var_b = func_b(1,2,3);
var_c = func_c(1,2,3);

while (1);

When the program is linked, the linker generates a call tree which it outputs to the map file.

?C_C51STARTUP               ----- -----  ----- -----
  +--> ?PR?MAIN?MAIN

MAIN/MAIN                   ----- -----  0008H 000EH
  +--> ?PR?FUNC_A?MAIN
  +--> ?PR?FUNC_B?MAIN
  +--> ?PR?FUNC_C?MAIN

FUNC_A/MAIN                 ----- -----  000FH 0011H

FUNC_B/MAIN                 ----- -----  000FH 0014H

FUNC_C/MAIN                 ----- -----  000FH 001AH

Based on the call tree, the linker reserves the memory used by the functions' arguments and local variables. The linker creates several special Overlay Groups (BIT_GROUP, DATA_GROUP, and so on) that contain the overlaid segments.

As you can see from the call tree above, the DATA_GROUP for func_a, func_b, and func_c starts at 000Fh. This shows that the linker believes the arguments and variables for these functions may be safely overlaid. Refer to the memory map for the memory range used by the _DATA_GROUP_.


* * * * * * * * * * *   D A T A   M E M O R Y   * * * * * * * * * * * * *
000000H   000007H   000008H   ---    AT..     DATA           "REG BANK 0"
000008H   00001AH   000013H   BYTE   UNIT     DATA           _DATA_GROUP_
00001BH   00001BH   000001H   BYTE   UNIT     IDATA          ?STACK


  • The linker generates overlay information that is accurate. However, in some instances the default analysis of the call tree is ineffective or incorrect. This occurs with functions that are called by both the main program and an interrupt and with functions called through function pointers.
  • Functions that are called by the main program root and by an interrupt service routine or functions that are called by two or more interrupts may not be overlaid.
  • Functions called through pointers require special handling within the linker in order for overlaying to work properly. This topic is discussed in Function Pointers.
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.