AnsweredAssumed Answered

Return value of function disappears (not allways)

Question asked by florian wehmeyer on Aug 4, 2008
Latest reply on Nov 27, 2008 by florian wehmeyer
   
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


Outcomes