AnsweredAssumed Answered

problem with compiler and pass-parameter - 9S08AW48 - USB multilink - CW6.2

Question asked by Mauro Girardi on Feb 13, 2009
Latest reply on Feb 14, 2009 by CompilerGuru
I'm working with 9S08AW48 micro with CodeWarrior 6.2, USB multilink interface for HCS08 and my embedded target.

I've a problem with the compiler options (I think) and the parameter passed to / from a function; the instructions, for example, are:

    Key = CheckKeyPressed();

(I've already tried to declare the variable "Key" static and file global, function-internal, but nothing)

The function "CheckKeyPressed" calculates the correct value: this value will be returned by "return KeyPressed", but the value I will see after the returning, is different from that one that i see in the function just before exiting.

The code for CheckKeyPressed() is:

function CheckKeyPressed() {
  // variable declaration ...

  index = getReg8(PTGD) & 0x0F;
  KeyPressed = Keyboard[index];

  return KeyPressed;    //KeyPressed has the correct value...

Key = CheckKeyPressed();  //"Key" receives a wrong value...

I've tried to check the "Disable Optimizations" flag in the Compiler tab of the "Edit->Standard Setting" menu, but no change in the simulation occurs.
Can anyone help me? I think there are some problems related to compiler optimisation and parameter-passing.

Thanks in advance for any suggestion.