Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

hello world - strange variables behavior

Hello,

I'm new to nios2 developpement and i'm having problems running the simple hello_world exemple :

When I lauch this code :

int main()
{
  unsigned char i,j,k;
  printf("Hello from Nios II!\n");
  while(1){
      i++;
      j++;
      k++;
      if(k==100){
       printf("a"); 
      }
  }
  return 0;
}
in the debugger, i can see that the 'i' variable is incrementing correctly, but the 'j' variable always have the value 203 and the 'k'variable always have the value 0.

Although i cant see the 'k' value changing, the program does go in the if statement.

Could anyone explain to me why i cant monitor correctly the variables values?

Thanks

ps: running this program, i also have an other problem regarding the console ouput as described in this post : alteraforum.com/forum/showthread.php?t=27499. I supposed it could be related

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    but why can I read 'i' correctly but not 'j' and 'k' ?

    The thing is, i noticed this problem is some other project where i really needed to read back some avalon-slave-module registers values. I was getting really strange values so i then tried to run the simple hello_world on my board to see if i still had problems.

    could the problem come from a bad sopc builder configuration ?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Look at the generated code...

    gdb can't really guarantee to give you the values of variables that are in registers.

    Although if you aren't compiling with -O2 (you really should use -O2 or -O3) then it is likely that all the expected code (including all the load/stores from stack for the local variables) is actually generated.

    Marking global data 'volatile' will force all references in the C source to generate load/store instructions.