[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Program Space String & optimization

From: bolet (sent by Nabble.com)
Subject: [avr-gcc-list] Program Space String & optimization
Date: Wed, 14 Dec 2005 01:42:47 -0800 (PST)

Hi, I'm new in AVR-gcc programming. Sorry if this question is too obious
(and sorry for my english too...)

 I'm just making some test to know how to access Flash strings. The program uses one interrupt to sends chars until end of string.
 The 'end of string' is checked in 'main' (just for test purposes).

 The program works OK without optimization. It doesn't work with optimization (-o1). The code is:

const char P_Txt[] PROGMEM = "Just a test..";
volatile PGM_P txt= P_Txt;

int main (void)

  ...Init code ... (reg setup & enable int)

   do{} while( (a=pgm_read_byte(txt)) );  // Wait for null char
   cli();                                 //Disable int
   for (;;);                              // Do nothing

    UDR0=pgm_read_byte(txt++);  //Send a byte and increment  pointer

The 'do while' assembler code generated (with -o1) :

+00000041:   91E00100    LDS     R30,0x0100
+00000043:   91F00101    LDS     R31,0x0101
+00000045:   9184           LPM     R24,Z            
51:          do{} while( (a=pgm_read_byte(txt)) );  // Wait for null char
+00000046:   2388          TST     R24    
+00000047:   F7F1           BRNE    PC-0x01          Branch if not equal

52:          cli();                                                  //Disable int

 As you can see, the LPM instruction is outside the loop, so this is an infinite loop.

 -What's wrong with this code?

 -Which is this the correct way to  work with flash data?

  Any suggestion would be greatly appreciated.



Sent from the AVR - gcc forum at Nabble.com:
Program Space String & optimization
reply via email to

[Prev in Thread] Current Thread [Next in Thread]