Jump to content
Sign in to follow this  

Not able to update SP and PC using inline assembly in MSP430-GCC

Recommended Posts

I am writing a simple task scheduler for my MSP430F5529 USB launchpad. I need to update stack pointer(SP), then enable interrupts and then update program counter (PC). But I am getting an error with my inline asmebly code.


    void start_scheduler(void)
      asm volatile("mov.w task1stack, SP \n"
                   "EINT \n"
                   "mov.w func1, PC \n"

 - task1stack is the stack area for the task execution. It is an array.
 - func1 is a function
 - instead of uppercase for 'SP' and 'PC', I tried lowercase also. But the error was present.

But with the above code, compiler is showing the below error

    kernel.c:(.text+0x8e): undefined reference to `SP'
    kernel.c:(.text+0x96): undefined reference to `PC'


 1. How to update SP and PC ?
 2. Can "mov.w task1stack, SP \n" copy array address to SP ? Is my syntax correct ?
 3. Can "mov.w func1, PC \n" copy the func1 address to PC? Is my syntax correct ?

Share this post

Link to post
Share on other sites

The issue is that PC and SP are just aliases for registers.

Just check any MSP430 datasheet (short-form description), or the CPU chapter in the family datasheet


PC == R0, and SP == R1, also SR == R2


if you want to use SP instead of R1 then you'll have to define the equivalence yourself.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...