[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] avr-g++ 4.3.2 and pgmspace.h
From: |
Kövesdi György |
Subject: |
[avr-gcc-list] avr-g++ 4.3.2 and pgmspace.h |
Date: |
Wed, 4 Mar 2009 10:34:57 +0100 |
User-agent: |
KMail/1.9.9 |
Hi,
I tried to store some data in flash memory using pgmspace.h.
It works well in C programs but I found that using C++ the things go wrong.
My sample code is:
$> cat x.c
#include <avr/io.h>
#include <avr/pgmspace.h>
prog_uint8_t table[] = {
0x01,
0x02,
0x03
};
uint8_t x;
void test(uint8_t index)
{
x=pgm_read_byte_near(table+index);
}
int main()
{
}
If it is compiled by avr-gcc, the result seems good:
$> avr-gcc -mmcu=attiny26 -Os x.c -o x
$> avr-objdump -d x
...
00000018 <table>:
18: 01 02 03 00 ....
...
00000052 <test>:
52: e8 e1 ldi r30, 0x18 ; 24
54: f0 e0 ldi r31, 0x00 ; 0
56: e8 0f add r30, r24
58: f1 1d adc r31, r1
5a: c8 95 lpm
5c: e0 2d mov r30, r0
5e: e0 93 60 00 sts 0x0060, r30
62: 08 95 ret
...
The table address seems correct here.
But using C++:
$> avr-g++ -mmcu=attiny26 -Os x.c -o x
$> avr-objdump -d x
...
0000004e <_Z4testh>:
4e: e0 e6 ldi r30, 0x60 ; 96
50: f0 e0 ldi r31, 0x00 ; 0
52: e8 0f add r30, r24
54: f1 1d adc r31, r1
56: c8 95 lpm
58: e0 2d mov r30, r0
5a: e0 93 64 00 sts 0x0064, r30
5e: 08 95 ret
...
The table seems now stored in the data segment.
Other MCU types give the same result.
Tanx in advance
K. Gy.
- [avr-gcc-list] avr-g++ 4.3.2 and pgmspace.h,
Kövesdi György <=