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.

Can store data to SP in my assembly function

Hi all

    In my asm function, I want to store the A10-A15 to SP at beginning, and before return I will read back the data from SP.

   Following is my test function.      My program flow is

     .... // other functions

   stackTest();

    .... // other functions

  when compile program as debug, the program can run correctly. But is compile as release, the program can't stop, as the PC is point to wrong address.

_stackTest:
;<Cycle 1>
STDW .D2T1 A11:A10, *B15_SP--
;<Cycle 2>
STDW .D2T1 A13:A12, *B15_SP--
;<Cycle 3>
STDW .D2T1 A15_FP:A14, *B15_SP--
;<Cycle 4>
ADD .S1 A4_a, A4_a, A14_sdf
;<Cycle 5>
LDDW .D2T1 *B15_SP++, A15:A14_sdf
;<Cycle 6>
LDDW .D2T1 *B15_SP++, A13:A12
;<Cycle 7>
LDDW .D2T1 *B15_SP++, A11:A10
;<Cycle 8>
NOP

;<Cycle 9>
NOP

;<Cycle 10>
NOP

;<Cycle 11>
NOP
;<Cycle 12>
B .S2 B3_retAddr
;<Cycle 13>
NOP

;<Cycle 14>
NOP

;<Cycle 15>
NOP

;<Cycle 16>
NOP

;<Cycle 17>
NOP

  • Hi,

    I suppose you are using a C6X target. The EABI sprab86, §4.4.1say:

    The double word (8 bytes) at the bottom of the frame spans a frame boundary. That is, the first word is in
    the callee's frame but the second is in the caller's frame, so neither can use it to store a double word

    Something similar is in the compiler manual spru187 §7.5.1

    So it seems to me that your first STDW is not conforming to the ABI.

    Try to add a dummy single register push like:

        STW B3,*SP--[2]

    Maybe in debug the caller stack layout if different and the first STDW don't overwrite any vital informatio.

  • Eric Mao said:
    when compile program as debug, the program can run correctly. But is compile as release, the program can't stop, as the PC is point to wrong address.

    I presume that under debug configuration, your build uses -g,  and under release configuration, your build does not use -g.  You're saying that this hand coded assembly function acts differently based on whether you build with -g or not.  Is that right?  I don't see how that is possible.  Thus, I suspect the problem is occurring somewhere else, and the first time you see it in when this function runs.

    Thanks and regards,

    -George