I have the following function calls and the number of bytes allocated on the local stack for each function. main() { 8.1 bytes allocated in local scope; call foo1() } foo1{ 49 bytes allocated call foo2() } foo2{ 278 bytes allocated call foo3() } foo3{ 61 bytes allocated call foo4() } foo4{ 28 bytes allocated call foo5() } foo5{ 24 bytes allocated } Total allocated is 448.1 bytes. Is this too big? I get really funny behavior in foo5 that I normally do not get. Funny behavior like values in foo4 when foo5 returns are blown away.
Assuming you're actually correct that this many bytes are allocated on the stack, then your program would be completely broken, and the tools would have refused to build it (you'ld have blown the IDATA segment's size). No 8051 has 400+ bytes of stack. Which almost certainly means your analysis is incorrect. But yes, if you have too much local data, in a deep call tree like this, you'll run into problems like those you observed. You'll have to move some of the larger objects away from the stack and into XDATA.
You realise that C51 - unlike "normal" 'C' compilers - does not use the stack for parameters and locals...? See the manual
does not use the stack for parameters and locals. Well, given that call tree, even Keil C51 will have a hard time overlaying them all to fit them into 256 bytes of combined DATA/IDATA space, as none of them would appear to be overlayable, from what he wrote.
"C51 will have a hard time overlaying them all to fit them into 256 bytes of combined DATA/IDATA space" Where it would try to fit them would depend on the memory model