Hello Dileep,
By default, the PRM file uses the STACKSIZE parameter, which means that the normal location of the stack is always unpredictable. This is because the bottom of the stack commences immediately following your global and static variables. The stack location can be totally predictable if you make use of the STACKTOP parameter, rather than STACKSIZE. You will also need to explicitly define a stack segment within the PRM file so that an error message will occur should the variables happen to stray into the stack segment. This should simplify your stack pointer manipulations.
SEGMENTS
Z_RAM = READ_WRITE 0x0080 TO 0x00FF
RAM = READ_WRITE 0x0100 TO 0x0FFF
STACK_SEG = READ_WRITE 0x1000 TO 0x107F
...
END
...
STACKTOP 0x107F
VECTOR 0 _Startup
I might suggest that you place the temporary stack within page zero whilst you test the remainder of RAM memory. You can then place the stack at the normal location, and then proceed to test page zero RAM.
Adjusting the stack pointer can easily be done with HLI assembly code - you could define some macros -
#define TEST_STACK __asm ldhx #0x0100; __asm txs
#define NORM_STACK __asm ldhx #0x1080; __asm txs
In case you are wondering, the addresses shown above are correct since the stack pointer will be decremented by one from these values (the operation of the TXS instruction).
Regards,
Mac