I have a question. How to know maximum stack of my program and stack overflow? beacause my program can lock when power have unstatable.
Once the power becomes unstable, anything can happen A point worth emphasizing. For example, the SP could still be correct, but the memory to which is points changes values due to lack of power. Or the ALU gets the correct SP, and mangles the value while processing the instruction. There's just no way to guarantee that the chip will work correctly in this situation, or even that it will fail the same way every time. If you have external devices on the board, you don't even know whether or not they have valid power, either; even if the processor core works, the rest of the board might not. If handling loss of power is a design requirement, then the power supply has to deliver a power-fail signal to the CPU before falling below the minimum Vcc, and also guarantee enough capacitance in the supply to keep that voltage above the minimum for long enough for the CPU to shut down cleanly. Trying to detect power failure by having the CPU monitor itself for improper behavior won't work.
If I assume that stack pointer point to wrong address in unstable power, how to know stack pointer be right or wrong rephrasing the question "how can I fix hardware in software" answer "you can't" Erik
"having the CPU monitor itself for improper behavior won't work" Not only are you trying to have the CPU monitor itself for improper behaviour, but you are trying to have the CPU monitor itself for improper behaviour whilst behaving improperly!!! :-0 The word "Doomed!" springs to mind...