Odd simulator behavior (AVR Studio) [solved]

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm posting here because I'm guessing this is a source code problem. Furthermore, even though I use ICCAVR, I'm also guessing this is a generic C problem. I'm not exactly a newb, but I am rusty. Anyway, here's the problem:

void main(void)
{
	 unsigned int i=1, G;
	 unsigned char red[] =     "       Red      ";
	 unsigned char green[] =   "      Green     ";
	 unsigned char blue[] =    "      Blue      ";
	 unsigned char orange[] =  "     Orange     ";
	 unsigned char yellow[] =  "     Yellow     ";
	 unsigned char brown[] =   "      Brown     ";
	 unsigned char empty[] =   "      Empty     ";
	 unsigned char unknown[] = "     Unknown    ";
	 ++i;
	 i = 7;
    G = 7;
//	 i = LEFT_0_D2;
 	 init_devices();

If I single-step through this, everything's fine until ++i. When I single-step past that line, i is properly incremented, but the simulator advances to G = 7, skipping i = 7. If I single-step again, G is set to 7 and the simulator advances to init_devices(), as it should. Why does it skip i = 7 (and I have the same problem if it's i++, or if the ++i line is removed entirely)? If I swap the i = 7 and G = 7 lines, the simulator skips both. I know this code is a little meaningless but I reduced the actual code to this test case to illustrate the problem. I actually want to set i to a preprocessor constant as in the commented line, but when that didn't work I narrowed it down to this issue.

Thanks for your help, and I apologize if this belongs somewhere else, I'll delete it if it does (and I can figure out how ;-) ).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The optimizer is probably removing all the useless code ( i and G aren't used anywhere else in the code ). Declare both as static unsigned int in main() or declare them like you did but OUTSIDE of main(). Your *.lss file will show that such code sections aren't even in the file ! Compare THAT file before and after my code changes.

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

Last Edited: Wed. Apr 27, 2011 - 09:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What happens when you turn of any optimization?

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

indianajones11:

That was it. Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You're welcome, and I suggest you get to the tutorial forum and read the "volatile" lesson when you can. You'll need it when you dive into ISR. Unless you already know about volatile / ISRs. :wink:

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the suggestion, I. Can you point me to it? If I search on relevant terms I get a lot of hits.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

tutorial forum = Avr Tutorials forum: https://www.avrfreaks.net/index.p...

That forum is a good place to be for alot of stuff. So's here to up ya game on C programming:
https://www.avrfreaks.net/index.p...

Quote:
I'll delete it if it does (and I can figure out how Wink ).
You can delete a post by hitting the 'x' that's in the lower right corner of your post ( if there are no posts below you ).

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1