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.

Variable Data being overwritten!! in C6713 DSP program

I am using Code Composer Studio with TMS320C6713 DSP with C++. This code is part of a function. the only thing that goes wrong in this loop is tempBX. tempBX is accurately initialized with 0.0. Later on, within the loop its value is accumulated, and that too works fine. When we are about to assign the value of tempBX to BXA[indx1], the value in tempBX changes automatically e.g.(before this instruction if tempBX = 0.0021454, then after this instruction, it is 1.234532e+27 etc.). I think it is some sort of memory management proble. but somebody plz help me out here....

thanx..

here is the code

 

 

..........

.........

    int indx1 = 0;
    float tempBX= 0.0;
    for (ccc=0;ccc <= dimensions-win;ccc++)
    {
        for (rrr=0; rrr <= dimensions-win; rrr++)
        {      
            tempBX = 0.0;
            for (cwin=0;cwin<=win-1;cwin++)
            {
                for (rwin=0;rwin<=win-1;rwin++)
                {
                        tempBX = tempBX + APB22[((ccc+cwin)*dimensions)+(rwin+rrr)];
                }
            }
            BXA[indx1]=tempBX;
            indx1=indx1+1;
        }
    }

 

  • Hello

    is the  BXA[] local or global variable?

    if local, then writing to BXA[] (i.e. - into stack!) can corrupt other local

    variables, for exmpl. - tempBX or indx1 (results of corrupting indx1 are more seriously)

    regards

    Michael

     

  • You will have to tell me how you drew the box around your code. That is a very nice effect.

    adnan khan said:

    When we are about to assign the value of tempBX to BXA[indx1], the value in tempBX changes automatically e.g.(before this instruction if tempBX = 0.0021454, then after this instruction, it is 1.234532e+27 etc.).

    It sounds like you are saying that when you do source-level single-stepping and observe the value of tempBX, it is 0.002... before executing the BXA[]=tempBX; line. And after executing that line by source-level single-stepping, the value is 1.23..e+27. Is this understanding correct?

    What value gets stored to BXA[indx1] by that line of code? Is it the 0.002... or the 1.23..e+27 or some other value?

    With optimization, it is possible for a variable to lose context after it is used. In your code example, the value in tempBX is not needed after this assignment instruction, so it could make sense for it to be reused or discarded in some way.

    Do you get this same result compiling with the default Debug Build Configuration, with no optimization and full debug?

    Does this happen on every iteration of the "for(rrr)" loop?

  • Along the lines of what Randy discusses, if you just "step over" the function, i.e. don't step through each line of it, do you get the proper result out of it?  It's not clear to me whether the compiled code is actually generating erroneous results or if you're just seeing some abnormalities as you step through the code (this is somewhat expected as optimization increases).