i am not sure if the stack is overflow in my project. thank a lot!
Even if you don't notice problems you always should have an idea about stack usage, it is the only way to rely on your program. The used stack is a dynamic characteristic so you only get this information at execution time. I will assume large memory model... The first step is determine the maximum available stack, you can get this value from map file, look for STACK keyword, for example: IDATA 0030H 0001H UNIT STACK The space between 30H and the end of internal memory (128 or 256 bytes)will be your available stack. 1/ Firts option is manual calculation: determine the function call tree and add 2 bytes per call (5 bytes if you use interbank function call). In addition add the stack usage of ISR (more calls and push/pop instructions) 2/Other option is directly read the SP value at the deepest points of your call function tree. You can estimate the risks. 3/ A third option, that a friend touch, me is very interesting. You have to initialise the IDATA with a known value "0x55". Later, at any point of ccall function tree, you can scan the idata and determine where the 0x55 appears and so the unused stack. This method even determine the stack usage of ISR (typically more complicate) This last method is still more powerfull... If you get a crash or a reset (perhaps you have a watchdog) and in systems where there is no RAM initialisation you can at start up take the "photo" of the crash and determine the stack usage. I hope all this useful for you. Thanks
I have a qustion: What is usage of the five bytes of ISR? And when it enter ISR in main procedure, how do Keil C51 to manager stack? push five bytes directly? Thx
What is usage of the five bytes of ISR? What 5 bytes? Erik
"What is usage of the five bytes of ISR?" Nobody said anything about five bytes. What five bytes are you talking about? "And when it enter ISR in main procedure, how do Keil C51 to manager stack? push five bytes directly?" If you write your ISR in C, then the compiler generates PUSH/POP instructions to save and restore whatever processor context is required. If you want to "see" it in action, then generate an assembly listing.
In C51.pdf it is said: The contents of the SFR ACC, B, DPH, DPL, and PSW, when required, are saved on the stack at the function invocation time. And I try to analyze stack while enterd ISR function, it make me so comfused. I want to konw what infomation is pushed to stack while enter ISR. thx for you so quickly replies. I am a fresh, i want to study assemble. wu~~~
View all questions in Keil forum