This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

local stack space and nested function calls

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.

Parents
  • 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.

Reply
  • 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.

Children
No data