[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] avr-gcc and C++ ?
From: |
Arreckx |
Subject: |
Re: [avr-gcc-list] avr-gcc and C++ ? |
Date: |
Tue, 3 Apr 2001 19:00:11 +0100 |
I am currently working on the C++ support for the AVR.
Indeed, the SRAM is limited (unless you add external RAM), but careful C++
design can be very efficient.
I have built the avr-g++ successfully (Windows and Linux) and I can compile
C++ files. I used the source from http://www.combio.de/avr/ to which I added
the g++ branch. I use cygwin to build in Windows, and everything works out
of the box.
What is good is that this compiler is the latest gcc and is very close to
the standard, and since Avr uses ELF format (rather than COFF), templates
and inline are dealt with in style. Rtti and exceptions are missing. But
this is a good thing. Gcc exceptions are enormous and C++ exception should
never be used on small and average size embedded system. Rtti will stop
developer from using dynamic cast, and probably multiple inheritance,
another good thing !
Unfortunately, I haven't manage to build the stdlibc++. This library is need
for a lot of the built-in C++ stuff, like calling constructors of global or
static object instances etc... configure is failing.
I don't think the stdlibc++ is right for the AVR anyway.
So what was done for libc will have to be done for libstdc++. I am looking
for buddies to help me with this task.
To prove what I was saying, here is the standard waggle test I always do on
a new target to check it is alive, but in C++.
#include <inttypes.h>
#include <io.h>
class waggle
{
// Construction
public:
explicit waggle( uint8_t port ) : _port(port) {}
// Data members
private:
uint8_t _port;
// Accessor
public:
uint8_t getPort() const
{ return _port; }
// Operation
public:
void start( const uint8_t bit ) const;
};
void waggle::start( const uint8_t bit ) const
{
for (;;)
{
__mmio((_port)) |= BV((bit));
__mmio((_port)) &= ~BV((bit));
}
}
static const uint8_t port = PORTC;
int main()
{
waggle Waggler( port );
Waggler.start( 4 );
return 0;
}
and the corresponding assembly it generates :
Disassembly of section .text:
00000000 <main>:
0: ce ef ldi r28, 0xFE ; 254
2: df e0 ldi r29, 0x0F ; 15
4: de bf out 0x3e, r29 ; 62
6: cd bf out 0x3d, r28 ; 61
8: 25 e1 ldi r18, 0x15 ; 21
a: 29 83 std Y+1, r18 ; 0x01
c: 60 e0 ldi r22, 0x00 ; 0
e: 8c 2f mov r24, r28
10: 9d 2f mov r25, r29
12: 01 96 adiw r24, 0x01 ; 1
14: 03 d0 rcall .+6 ; 0x1c
16: 80 e0 ldi r24, 0x00 ; 0
18: 90 e0 ldi r25, 0x00 ; 0
0000001a <__stop_progIi__>:
1a: ff cf rjmp .-2 ; 0x1a
0000001c <waggle::start(unsigned char) const>:
1c: b9 2f mov r27, r25
1e: a8 2f mov r26, r24
20: 46 2f mov r20, r22
22: 21 e0 ldi r18, 0x01 ; 1
24: 30 e0 ldi r19, 0x00 ; 0
26: 02 c0 rjmp .+4 ; 0x2c
28: 22 0f add r18, r18
2a: 33 1f adc r19, r19
2c: 4a 95 dec r20
2e: e2 f7 brpl .-8 ; 0x28
30: 92 2f mov r25, r18
32: 90 95 com r25
34: 6c 91 ld r22, X
36: e6 2f mov r30, r22
38: ff 27 eor r31, r31
3a: 50 a1 ldd r21, Z+32 ; 0x20
3c: 52 2b or r21, r18
3e: 50 a3 std Z+32, r21 ; 0x20
40: 4c 91 ld r20, X
42: e4 2f mov r30, r20
44: ff 27 eor r31, r31
46: 30 a1 ldd r19, Z+32 ; 0x20
48: 39 23 and r19, r25
4a: 30 a3 std Z+32, r19 ; 0x20
4c: f3 cf rjmp .-26 ; 0x34
4e: 08 95 ret
Disassembly of section .data:
Bill.