Return value of function disappears (not allways)

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Return value of function disappears (not allways)

ソリューションへジャンプ
2,158件の閲覧回数
flow
Contributor I
   
Hi everybody.

This is not a problem of missing function declaration or missing header or "implicit parameter-declarations",
as I enabled the -Wpd option.


problem:

I call following function:

unsigned int readSRAM_int(unsigned long add);


twice in a loop. Sadly, only the second time (better : all odd times) in the loop when the function is called, it really returns the unsigned int value into the local variable of the calling function.
In the function itself its everything going well, as explained in the compiler manual, the return value is stored into D register.
Looking in the Assembly window of the debugger (BDM) I can see, when this happens, that the "STD" instruction simply isn't present, that's why the return value is lost.


I disabled any kind of code optimization and still the return value is lost !! And still all odd times I get the return value... Seems problem of compiler optimization, doesn't ??

Here's part of my code:


    sram_add = (unsigned long) (add + 3);              

    for(i=0; i< (bitcounter*2); i+=2){

      //get length of "send" part:
      tempint2 = readSRAM_int(sram_add);
      asm STD tempint2;                       //dumb help !!!!!!!!!!!!!!!!!!!!!!

      ulong1 =  (unsigned long)  (carrier * ((unsigned long) tempint2));  // length * carrier period
      ulong1 *= 2412;
      ulong1 /= 100000; // /1000 / 10 = temp in multiples of 10 us

      if(ulong1 < (0xFFFF)){
          buffer[i+offset] = (unsigned int) (ulong1);          
          }


      //calculate "not send" part:
      sram_add++;
      tempint2 = readSRAM_int(sram_add);

      ulong1 =  (unsigned long)  (carrier * ((unsigned long) tempint2));  // length * carrier period
      ulong1 *= 2412;
      ulong1 /= 100000;                 // val in mults of 10 us

      if(ulong1 < (0xFFFF)){ //(0xFFFF+60)
          buffer[i+offset+1] = (unsigned int) (ulong1);     
          }

      sram_add++;
      }


In the very desperate hours I finally did the STD instruction manually, so it "works fine"!!!!!!!! What a dumb solution :smileysad:
And whats even more dumb : now that I do it manually, the compiler also does.. 2 times the STD....

Any suggestions ?? Please help..

Thanks


ラベル(1)
タグ(1)
0 件の賞賛
返信
1 解決策
1,021件の閲覧回数
flow
Contributor I

OK, just to terminate this thread case somebody is looking to it:

Yes, it was the case that the values of variables weren't displayed correctly,
to add the -onu option in the compiler options resolved the problem !!

Thanks

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
1,021件の閲覧回数
CompilerGuru
NXP Employee
NXP Employee
Is the issue that the value of the local variable tempint2 is not displayed correctly, or is the issue that the code does not run as expected?
I guess its the first one, as the tempint2 variable is only used immediately after it is assigned, and later it is always overwritten. So the compiler can just not store it in the local variable, but I see that this is not so nice for debugging. I would try to disable the -onu optimization and see if this helps. If not, (not sure), making the variable volatile  (I don't like that) or checking the value in the register (with a big comment instead of the HLI STD).


Daniel
0 件の賞賛
返信
1,022件の閲覧回数
flow
Contributor I

OK, just to terminate this thread case somebody is looking to it:

Yes, it was the case that the values of variables weren't displayed correctly,
to add the -onu option in the compiler options resolved the problem !!

Thanks

0 件の賞賛
返信