Hello All,
Greetings.
This is my first project using the arduino. And The code/machine doesnot behave as intended. So I compiled in 'verbose' mode, 'located' the elf file generated by the IDE, and disassembled (using avr-objdump) it to inspect the code generated by the cross-compiler.
For the method that is defined as under:
void operateBottleStopper (char bottle, String oc) {
if (oc.equals("open")) {
if (bottle == 'l') {
digitalWrite (9, HIGH);
digitalWrite (8, HIGH);
} else {
digitalWrite (15, HIGH);
digitalWrite (14, HIGH);
}
} else {
if (bottle == 'l') {
digitalWrite (9, LOW);
digitalWrite (8, LOW);
} else {
digitalWrite (15, LOW);
digitalWrite (14, LOW);
}
}
delay (200);
}
------method defination ends here -----
I discover that the corresponding assembly code reads as follows:
00000962 <_Z20operateBottleStopperc6String>:
962: cf 93 push r28
964: c8 2f mov r28, r24
966: cb 01 movw r24, r22
968: 63 e4 ldi r22, 0x43 ; 67
96a: 71 e0 ldi r23, 0x01 ; 1
96c: 0e 94 62 04 call 0x8c4 ; 0x8c4 <_ZNK6String6equalsEPKc>
970: 88 23 and r24, r24
972: b9 f0 breq .+46 ; 0x9a2 <_Z20operateBottleStopperc6String+0x40>
974: 61 e0 ldi r22, 0x01 ; 1
976: cc 36 cpi r28, 0x6C ; 108
978: 71 f4 brne .+28 ; 0x996 <_Z20operateBottleStopperc6String+0x34>
97a: 89 e0 ldi r24, 0x09 ; 9
97c: 0e 94 de 00 call 0x1bc ; 0x1bc <digitalWrite>
980: 61 e0 ldi r22, 0x01 ; 1
982: 88 e0 ldi r24, 0x08 ; 8
984: 0e 94 de 00 call 0x1bc ; 0x1bc <digitalWrite>
988: 68 ec ldi r22, 0xC8 ; 200
98a: 70 e0 ldi r23, 0x00 ; 0
98c: 80 e0 ldi r24, 0x00 ; 0
98e: 90 e0 ldi r25, 0x00 ; 0
990: cf 91 pop r28
992: 0c 94 62 01 jmp 0x2c4 ; 0x2c4 <delay>
996: 8f e0 ldi r24, 0x0F ; 15
998: 0e 94 de 00 call 0x1bc ; 0x1bc <digitalWrite>
99c: 61 e0 ldi r22, 0x01 ; 1
99e: 8e e0 ldi r24, 0x0E ; 14
9a0: f1 cf rjmp .-30 ; 0x984 <_Z20operateBottleStopperc6String+0x22>
9a2: 60 e0 ldi r22, 0x00 ; 0
9a4: cc 36 cpi r28, 0x6C ; 108
9a6: 29 f4 brne .+10 ; 0x9b2 <_Z20operateBottleStopperc6String+0x50>
9a8: 89 e0 ldi r24, 0x09 ; 9
9aa: 0e 94 de 00 call 0x1bc ; 0x1bc <digitalWrite>
9ae: 60 e0 ldi r22, 0x00 ; 0
9b0: e8 cf rjmp .-48 ; 0x982 <_Z20operateBottleStopperc6String+0x20>
9b2: 8f e0 ldi r24, 0x0F ; 15
9b4: 0e 94 de 00 call 0x1bc ; 0x1bc <digitalWrite>
9b8: 60 e0 ldi r22, 0x00 ; 0
9ba: f1 cf rjmp .-30 ; 0x99e <_Z20operateBottleStopperc6String+0x3c>
-------- excerpts from the disassembled elf file contents ends here --------
I notice that whereas the c-code is invoking the "digitalWrite" in 8 places, the generated code is invoking it in only 5 places ! On the face of it, does the translation look suspect to informed members of the community ? Also any advice/suggestions/corrections? I am using the Arduino IDE Version 1.8.8.
Thanks, and kind regards,
Vivek.