avr-gcc-list
[Top][All Lists]
Advanced

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

[avr-gcc-list] Constants in flash


From: Torsten Landschoff
Subject: [avr-gcc-list] Constants in flash
Date: Sun, 23 Oct 2005 20:04:58 +0200
User-agent: Mutt/1.5.9i

Hi *, 

In writing a boot loader for the ATmega128 I run into the following
problem: I have a function taking some kind of "format string" to 
describe the intended behaviour. I declare those as being in program 
memory. 

Because of that they end up in the highest 8kB of program memory. But I 
want to access them from program code. Problem is: When I take the
address I only get the lower 16 bits:

    #include <avr/pgmspace.h>
    void    f(void)
    {
            static const char format[] PROGMEM = "silly example";
            uint32_t address = (uint32_t) format;
            char first = pgm_read_byte_far(address);
    }

This ironically generates working code, which looks like this:

   6:simple.c      ****         uint32_t address = (uint32_t) format;
  91                    .LM2:
  92 0014 80E0                  ldi r24,lo8(format.0)
  93 0016 90E0                  ldi r25,hi8(format.0)
  94 0018 AA27                  clr r26
  95 001a 97FD                  sbrc r25,7
  96 001c A095                  com r26
  97 001e BA2F                  mov r27,r26
[register shuffling omitted]
 117                    /* #APP */
 118 0040 ABBF                  out 59, r26
 119 0042 FC01                  movw r30, r24
 120 0044 8791                  elpm r24, Z+
 121
 122                    /* #NOAPP */

For some reason the compiler thinks the address is signed which leads to 
working code (as long as the format is in the upper or lower 32kByte of
Flash). 

So it seems that in my case I don't have a problem. On the other hand I wonder
how I could infer the flash location of a so declared constant. Any hints?
BTW: Replacing the cast in the assignment to address with (uint16_t) leads
to non-working code in my case.


Greetings

        Torsten




reply via email to

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