Optimization flag and "relative jump to self"

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

After a forced separation from AVRs of several months I finally got a mega128 and a JTAGICE clone and can play with them again.

Now here's the problem - when I compile my code with the -O0 flag (no optimization as far as I know) it works perfectly. If I try any of the different performance optimization levels or the size optimization the program runs correctly till it reaches an ADC starting macro (initialization has been performed previously) I am using AVR Studio 4.13.522 with WinAVR 20070122.

//Start ADC conversion
	start_adc();

//Wait for end of conversion
	while(adc_idle!=255){}

The macro "start_adc();" is defined as follows, where adc_idle is a flag variable in my code and that may also be changed by the ADC interrupt service routine.

#define start_adc();	{ADCSRA|=(1<<adsc);\						adc_idle=0;}

Now from the disassembler window I figured out that the ADC is beign started and the flag (lying at location 0x016D) is being written by the following assembly code, but after that there is a relative jump of zero which basically stops the program forever at that line. I have no idea whether this is coming from some mistake in the while statement or from somewhere else? Can anyone help me in this because I'd rather like having my code optimized?

53:       	start_adc();
+0000020F:   9A36        SBI     0x06,6           Set bit in I/O register
+00000210:   9210016D    STS     0x016D,R1        Store direct to data space
+00000212:   CFFF        RJMP    PC-0x0000        Relative jump
+00000213:   1B99        SUB     R25,R25          Subtract without carry
+00000214:   E079        LDI     R23,0x09         Load immediate

Finally I have noticed in the disassmbly window that there are sections that are full of instructions but are marked as "no source" - are these data to be burnt into flash for initialization of variable and stored strings?

Nath

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

FAQ#1... volatile is your friend.

Please read the avr-libc FAQ.

The compiler figures out nobody could ever change the flag variable
again, so the net effect of waiting for it to become 255 is an
infinite loop.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

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

Damn! So stupid of me! :( I had the same problem over a year ago when using a TMS320 board in my engineering course, but too much time away from this stuff and I'm getting rusty!

I hope I don't keep making silly mistakes like these any more.

Thanks a lot Jörg!

Nath