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.

c28x - Modifying SP



Hello All,

I've looked at the docs and some example code - but would like to ask about how do directly modify the SP with preferably a MOV instruction in assembly -

i.e. -

XAR7 contains pointer

- I want to take the contents of XAR7 and MOV that directly to the SP -

The c28x family doesn't seem to have any LDI SP, Rx instructions - correct?

Does the c28x family have an SP alias that maybe I am missing - like R1 or something?

Here's an example to make my request clearer, just in case:

MOVW XAR7, @_pointer_thing ; load XAR7 with a pointer

MOVW SP, *XAR7  ; load SP with contents of XAR7

maybe something like this would work:

    MOV    AR1,*XAR 
    MOV    SP,AR1

Thanks,
johnw

 

  • John,

    I believe the instruction you're looking for is PUSH.  More information on it can be found at SPRU430 (current version is E).

    Something like:
    PUSH *XAR7++   //push xar7 onto the stack, increment stack and xar7
    is what you're looking to do I believe.


    Thanks,
    Brett

  • Brett,

     

    PUSH *XAR4++ ; Push the value pointed to by XAR4

    ; into the location pointed to

    ; by SP. Post-increment SP and XAR4

    ; by 1

     

    Nope - don't want any post-incrementing - also sounds like it treats what's in SP as a pointer. 

    what I need this this:

    *XAR7 = 0xabcd

    when completed - I want SP = 0xabcd .

    Thanks,
    John

     

  • Hi johnw

    what you need is this "MOV     @SP,AL" - moves contents of AL into SP and "MOV     AL,@SP" for vice-versa. It probably works with AR7 but not with XAR7 as XAR7 is 32-bit register and SP is 16-bit wide.

     

    Regards, Mitja

  • Hello Mitja,

    What's in the OP actually worked OK - 

    movl xar6, @_pointer_thingy

    movl xar0, *xar6

    mov sp, ar0

    Works OK - now to get the inverse of that working... - don't necessarily want to use the accumulator but may not have a choice.

    Note this is in cotext of the stack space which is confined to the lower 64KB in this architecture so the above should be an OK GP solution.

    Regards,
    johnw 

  • Mitja's code looks correct to me.

    johnw's code misses a proper setup of register DP at the beginning:  "MOVW DP, #_pointer_thingy".

    movl xar6, @_pointer_thingy   =>   uses direct adressing mode to load whatever 32-bit data is in memory "_pointer_thngy" into xar6. Direct addressing however requires to set the DP register to the correct page, BEFORE your can use direct addressing mode. In johnw's code register DP is not initialized. At the end xar6 will hold a 32-bit value from the current active page, but likely not the correct one..

    Regards

     

     

  • The correct page has been set up previously to the code that is in this example.  The question regards how to directly change the SP.

    In my OP - the original post, I had the right idea.   If you read that - you will notice nothing really new was suggested in this thread since the OP.

    movl xar6, @_pointer_thingy

    mov al, @sp

    mov *ar6, al

    Will store the SP into the address pointed to by _pointer_thingy.

    I am not sure why

    mov ar0, @sp doesn't work.

     I think it is more than obvious that the correct page has been set up previously to this code.

    Thanks for the discussion all!
    jwest