This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Initialisation of stack pointer

How do I initialise the stack pointer location to a memory location 0x80 instead of the default memory location.
Also how do i set the stack pointer to point to xdata locations.
I have tried to set the stack pointer in the c startup routine written by me,but the controller resets.Please solve my questions.
Thanks

  • How do I initialise the stack pointer location to a memory location 0x80 instead of the default memory location.
    The instruction

     mov sp,#80H 
    loads the value 80H into register SP. However, if you want the first byte to be stacked at address 80H, you should use
     mov sp,#7FH.
    Make sure you have enough (free!) internal RAM at address 80H and above. This is not the case for an 8031. In an 8031 the memory ends up at address 7FH. You also have to take in account that the stack grows upwards (to higher addresses).

    It is common practice to set the stack pointer to the last byte of used internal ram. The last byte of used ram may reside in DATA oder IDATA space. This gives you the maximum stack size.

    Also how do i set the stack pointer to point to xdata locations.

    You can't. Stack is always in internal memory.

    HHK