Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12687 Discussions

hello world - strange variables behavior

Altera_Forum
Honored Contributor II
1,335 Views

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
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
373 Views

Quite possibly the values are in registers and/or optimised away.

0 Kudos
Altera_Forum
Honored Contributor II
373 Views

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 ?
0 Kudos
Altera_Forum
Honored Contributor II
373 Views

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.
0 Kudos
Reply