Hi everybody,
I'm new to arduino and the forum and this is my first post. I hope I'm posting it in the right forum...
I started with my first project and my binary excess the maximum size to fit in the atmega168, so I had a look at the object files in the /applet folder of my sketch with avr-objdump and found something I think is weird. The constructors of every class are duplicated, they are created twice.
For example, if I do "avr-objdump -CD my_sketch.elf" I can see this for the HardwareSerial class:
000022c0 <HardwareSerial::HardwareSerial(unsigned char)>:
22c0: 08 95 ret
000022c2 <HardwareSerial::HardwareSerial(unsigned char)>:
22c2: 08 95 ret
000022c4 <HardwareSerial::printNumber(unsigned long, unsigned char)>:
22c4: cb 01 movw r24, r22
22c6: ba 01 movw r22, r20
22c8: 33 27 eor r19, r19
22ca: 44 27 eor r20, r20
22cc: 55 27 eor r21, r21
22ce: 0e 94 e6 12 call 0x25cc ; 0x25cc <printIntegerInBase>
22d2: 08 95 ret
...
You can see that the HardwareSerial constructor is duplicated, and I think this is wasting space, not much in this case, but if I look for one class with a more complex contructor this is worse:
0000010a <LCD4Bit::LCD4Bit(int)>:
10a: 70 93 0f 01 sts 0x010F, r23
10e: 60 93 0e 01 sts 0x010E, r22
112: 61 50 subi r22, 0x01 ; 1
114: 70 40 sbci r23, 0x00 ; 0
116: 62 30 cpi r22, 0x02 ; 2
118: 71 05 cpc r23, r1
11a: 30 f0 brcs .+12 ; 0x128 <LCD4Bit::LCD4Bit(int)+0x1e>
11c: 81 e0 ldi r24, 0x01 ; 1
11e: 90 e0 ldi r25, 0x00 ; 0
120: 90 93 0f 01 sts 0x010F, r25
124: 80 93 0e 01 sts 0x010E, r24
128: 08 95 ret
0000012a <LCD4Bit::LCD4Bit(int)>:
12a: 70 93 0f 01 sts 0x010F, r23
12e: 60 93 0e 01 sts 0x010E, r22
132: 61 50 subi r22, 0x01 ; 1
134: 70 40 sbci r23, 0x00 ; 0
136: 62 30 cpi r22, 0x02 ; 2
138: 71 05 cpc r23, r1
13a: 30 f0 brcs .+12 ; 0x148 <LCD4Bit::LCD4Bit(int)+0x1e>
13c: 81 e0 ldi r24, 0x01 ; 1
13e: 90 e0 ldi r25, 0x00 ; 0
140: 90 93 0f 01 sts 0x010F, r25
144: 80 93 0e 01 sts 0x010E, r24
148: 08 95 ret
0000014a <LCD4Bit::pulseEnablePin()>:
14a: 1f 93 push r17
14c: 61 e0 ldi r22, 0x01 ; 1
14e: 80 91 04 01 lds r24, 0x0104
152: 0e 94 52 15 call 0x2aa4 ; 0x2aa4 <digitalWrite>
156: 15 e0 ldi r17, 0x05 ; 5
I think the constructors should appear only once and this is wasting some of the limited space in the atmega168.
Does anyone know why this is happening? Is it normal?