stack calculation in microcontroller
This all depends on your compiler, the compiler options, and the microcontroller you are using. It may be a reasonable way to get an approximation of the stack usage, but it will not be completely accurate.

If you are running your code in an embedded operating system, it will often have the stack pointers for each thread readily accessible so that you can read it directly. If you are coding this on the "bare metal", then I suggest that you find out how to read the stack pointer directly, write an assembly code routine to read it out, and use that value in your checks. If you are using GCC, you can tell the compiler to embed this check at the start of every function automatically, using the "instrument-functions" option.

The way I often do it while developing is to allocate a lot of memory for the stack, then fill it with a special pattern that is unlikely to naturally appear in the stack. After my code has been running, I go through this area and search backwards until I reach the first value that is not my pattern, and then I can be pretty sure that this is the most stack that has been used. For this to be effective, you have to exercise all code paths during testing.

EDIT: I now see that you assume that the stack grows from a low address to a high address. This is often not the case. In particular, it is not true for your S12 microcontroller. Section 2.2.4 of the S12CPUV2 Reference Manual mentions that it grows from "downward", meaning that it starts out at a higher address and is decreased towards zero the more it is used.