This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430 Launchpad, CCS, Assembly Language: #__STACK_END Definition

Dear Sir:

      I was programming an "assembly language only" project using Code Composer Studio.

      The assembly language code, supplied by TI, refers to a command, #__STACK_END, that I would like to have defined explicitly.

      Below is a copy of the "template" code supplied by TI:

______________________________________________________________________________________________

; MSP430 Assembler Code Template for use with TI Code Composer Studio

;

;

;-------------------------------------------------------------------------------

            .cdecls C,LIST,

"msp430.h"       ; Include device header file

;-------------------------------------------------------------------------------

           

.text                           ; Assemble into program memory

            .retain                        

; Override ELF conditional linking

                                           

; and retain current section

            .retainrefs                    

; Additionally retain any sections

                                           

; that have references to current

                                           

; section

;-------------------------------------------------------------------------------

RESET       mov.w   #__STACK_END,SP        

; Initialize stackpointer

StopWDT     mov.w   #WDTPW|WDTHOLD,&WDTCTL 

; Stop watchdog timer

;-------------------------------------------------------------------------------

                                           

; Main loop here

;-------------------------------------------------------------------------------

 

;-------------------------------------------------------------------------------

;           Stack Pointer definition

;-------------------------------------------------------------------------------

           

.global __STACK_END

            .sect .stack

;-------------------------------------------------------------------------------

;           Interrupt Vectors

;-------------------------------------------------------------------------------

            .sect  

".reset"                ; MSP430 RESET Vector

           

.short  RESET

_____________________________________________________________________________________

 

Can anyone please explicitly define the command: #__STACK_END

in terms of its constituent instructions in assembly language?

 

  • Let me re-phrase the question,

    "Can anyone please explicitly define the command: #__STACK_END

    in terms of its constituent instructions in assembly language?"

    as:

    Can anyone please explicitly define the command: #__STACK_END in terms of its exact definition as a single instruction (eg. pointer to a memory address? - binary number) and then proceed to define how this code snippet:

    RESET       mov.w   #__STACK_END,SP

    operates to perform its intended "functionality" within the referenced "RESET label" operation?

  • __STACK_END is a symbol defined by the Linker, which is is assigned the end of the .stack section.

    See section 8.5.9.4 "Symbols Defined by the Linker" in the MSP430 Assembly Language Tools User's Guide.

  • ‘#’ denotes an immediate (constant) value: #1, #2, #label, #symbol. It gives a numerical value (which can be a memory address, but not the content of a memory address)  as source parameter to an assembly instruction.

    IIRC, __STACK_END is a symbol that is resolved by the linker, based on the linker script. Usually, it resolves to the target MSP’s end of ram.

    This symbol is a linker-specific convention and not portable across different IDEs.

    The quoted instruction initializes the top of stack to this value, usually the end of ram, so the stack can be used and grow from there downwards. Before this point, no call or push operations can be used, as the stack pointer will likely point to an area where there is no ram at all.

  • Dear Sirs:

         I would like to thank you both for your efforts and I appreciate your replies.   I have checked off that you have answered my question.   If I have another question pertaining to this question, I will create another post or see if I can revive this post.   Again, I would like to thank you for your efforts.

         Sincere Regards,

       

        

  • Hi.  I have this __STACK_END problem with the ARM Linker.  

    It is not resolving the symbol and I can't figure out why.  

    I am working on system.lib of starterware for the beaglebone.  

    Any ideas?

    thanks................dd

  • Hi. I have this __STACK_END problem with the ARM Linker.

    It is not resolving the symbol and I can't figure out why.

    I am working on system.lib of starterware for the beaglebone.

    Any ideas?

    thanks................dd
  • As told before, this symbol is resolved by the linker based on the information in the processor specific linker script. It may have changed the name or may have never been available for IAR at all (the thread was about CCS originally). As I said, this is a not portable thing and normally only used internally between linker and startup code. If you want to use it in your assembly code, then you'll have to figure out which symbol your specific linker version uses. And maybe need to change your code on every update of the IDE.

**Attention** This is a public forum