I tested the following code using the simulator for a HCS12DJ256. Not sure if this is what you are looking for though. Should be able to create a test project and paste this code into main.c
#include <hidef.h> /* common defines and macros */
#include <mc9s12dj256.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dj256b"
/* Define to turn on stack checking */
#define DEBUG_STACK
/* Macro to calculate amount of stack used */
#define STACK_CHECK asm PSHX; asm TSX; asm STX StackPtr; asm PULX;\
StackUsed = StackStart - StackPtr /*; asm BGND */
/* Macro to save stack start */
#define STACK_START asm PSHX; asm TSX; asm STX StackStart; asm PULX
/* Variables for stack checking only asllocated if DEBUG_STACK is defined */
#ifdef DEBUG_STACK
unsigned int StackPtr = 0;
unsigned int StackStart = 0;
unsigned int StackUsed = 0;
#endif
/* Just some variables */
int i;
int Array[100];
/* Just a function for testing stack usage */
void Function1(void){
int Array2[10];
/* If we are stack checking do it here */
#ifdef DEBUG_STACK
STACK_CHECK;
#endif
/* Do something */
for(i=0; i<10; i++){
Array[i] = i;
}
/* Use local array so compiler does not optimize it out */
Array2[0] = Array[5];
}
/* Main function */
void main(void) {
/* Get stack starting position */
#ifdef DEBUG_STACK
STACK_START;
#endif
/* Call test function */
Function1();
for(;
{} /* wait forever */
}