So are you looking for “What the ASM code looks like for the C code”?
The red_led(1) ASM code :
0000012c <red_led>:
12c: 51 9a sbi 0x0a, 1 ; 10
12e: 88 23 and r24, r24
130: 11 f0 breq .+4 ; 0x136 <red_led+0xa>
132: 59 98 cbi 0x0b, 1 ; 11
134: 08 95 ret
136: 59 9a sbi 0x0b, 1 ; 11
138: 08 95 ret
Here is the complete program C code:
/*
* led1: for the 3pi robot, Orangutan LV 168, Orangutan SV-xx8, Orangutan SVP,
* or Baby Orangutan B
*
* This program uses the OrangutanLEDs functions to control the red and green
* LEDs on the 3pi robot or Orangutan. It will also work to control the red
* LED on the Baby Orangutan B (which lacks a second, green LED).
*
* https://www.pololu.com/docs/0J20
* https://www.pololu.com
* https://forum.pololu.com
*/
int main()
{
while(1)
{
red_led(1); // red LED on
delay_ms(1000); // waits for a second
red_led(0); // red LED off
delay_ms(1000); // waits for a second
green_led(1); // green LED on (will not work on the Baby Orangutan)
delay_ms(500); // waits for 0.5 seconds
green_led(0); // green LED off (will not work on the Baby Orangutan)
delay_ms(500); // waits for 0.5 seconds
}
}
Becomes this ASM code:
LEDTest.elf: file format elf32-avr
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 000002d0 00000000 00000000 00000074 2**1
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .bss 00000007 00800100 00800100 00000344 2**0
ALLOC
2 .stab 00000498 00000000 00000000 00000344 2**2
CONTENTS, READONLY, DEBUGGING
3 .stabstr 00000b69 00000000 00000000 000007dc 2**0
CONTENTS, READONLY, DEBUGGING
4 .debug_aranges 000000b8 00000000 00000000 00001345 2**0
CONTENTS, READONLY, DEBUGGING
5 .debug_pubnames 000001b4 00000000 00000000 000013fd 2**0
CONTENTS, READONLY, DEBUGGING
6 .debug_info 00000555 00000000 00000000 000015b1 2**0
CONTENTS, READONLY, DEBUGGING
7 .debug_abbrev 000002e0 00000000 00000000 00001b06 2**0
CONTENTS, READONLY, DEBUGGING
8 .debug_line 00000462 00000000 00000000 00001de6 2**0
CONTENTS, READONLY, DEBUGGING
9 .debug_frame 00000130 00000000 00000000 00002248 2**2
CONTENTS, READONLY, DEBUGGING
10 .debug_str 0000034a 00000000 00000000 00002378 2**0
CONTENTS, READONLY, DEBUGGING
11 .debug_loc 0000001e 00000000 00000000 000026c2 2**0
CONTENTS, READONLY, DEBUGGING
12 .debug_ranges 000000a8 00000000 00000000 000026e0 2**0
CONTENTS, READONLY, DEBUGGING
Disassembly of section .text:
00000000 <__vectors>:
0: 0c 94 46 00 jmp 0x8c ; 0x8c <__ctors_end>
4: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
8: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
c: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
10: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
14: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
18: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
1c: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
20: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
24: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
28: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
2c: 0c 94 b4 00 jmp 0x168 ; 0x168 <__vector_11>
30: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
34: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
38: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
3c: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
40: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
44: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
48: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
4c: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
50: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
54: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
58: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
5c: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
60: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
64: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
68: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
6c: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
70: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
74: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
78: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
7c: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
80: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
84: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
88: 0c 94 65 00 jmp 0xca ; 0xca <__bad_interrupt>
0000008c <__ctors_end>:
8c: 11 24 eor r1, r1
8e: 1f be out 0x3f, r1 ; 63
90: cf ef ldi r28, 0xFF ; 255
92: d0 e4 ldi r29, 0x40 ; 64
94: de bf out 0x3e, r29 ; 62
96: cd bf out 0x3d, r28 ; 61
00000098 <__do_copy_data>:
98: 11 e0 ldi r17, 0x01 ; 1
9a: a0 e0 ldi r26, 0x00 ; 0
9c: b1 e0 ldi r27, 0x01 ; 1
9e: e0 ed ldi r30, 0xD0 ; 208
a0: f2 e0 ldi r31, 0x02 ; 2
a2: 00 e0 ldi r16, 0x00 ; 0
a4: 0b bf out 0x3b, r16 ; 59
a6: 02 c0 rjmp .+4 ; 0xac <__do_copy_data+0x14>
a8: 07 90 elpm r0, Z+
aa: 0d 92 st X+, r0
ac: a0 30 cpi r26, 0x00 ; 0
ae: b1 07 cpc r27, r17
b0: d9 f7 brne .-10 ; 0xa8 <__do_copy_data+0x10>
000000b2 <__do_clear_bss>:
b2: 11 e0 ldi r17, 0x01 ; 1
b4: a0 e0 ldi r26, 0x00 ; 0
b6: b1 e0 ldi r27, 0x01 ; 1
b8: 01 c0 rjmp .+2 ; 0xbc <.do_clear_bss_start>
000000ba <.do_clear_bss_loop>:
ba: 1d 92 st X+, r1
000000bc <.do_clear_bss_start>:
bc: a7 30 cpi r26, 0x07 ; 7
be: b1 07 cpc r27, r17
c0: e1 f7 brne .-8 ; 0xba <.do_clear_bss_loop>
c2: 0e 94 67 00 call 0xce ; 0xce <main>
c6: 0c 94 66 01 jmp 0x2cc ; 0x2cc <_exit>
000000ca <__bad_interrupt>:
ca: 0c 94 00 00 jmp 0 ; 0x0 <__vectors>
000000ce <main>:
* https://www.pololu.com
* https://forum.pololu.com
*/
int main()
{
ce: df 93 push r29
d0: cf 93 push r28
d2: cd b7 in r28, 0x3d ; 61
d4: de b7 in r29, 0x3e ; 62
while(1)
{
red_led(1); // red LED on
d6: 81 e0 ldi r24, 0x01 ; 1
d8: 0e 94 96 00 call 0x12c ; 0x12c <red_led>
delay_ms(1000); // waits for a second
dc: 88 ee ldi r24, 0xE8 ; 232
de: 93 e0 ldi r25, 0x03 ; 3
e0: 0e 94 f3 00 call 0x1e6 ; 0x1e6 <delay_ms>
red_led(0); // red LED off
e4: 80 e0 ldi r24, 0x00 ; 0
e6: 0e 94 96 00 call 0x12c ; 0x12c <red_led>
delay_ms(1000); // waits for a second
ea: 88 ee ldi r24, 0xE8 ; 232
ec: 93 e0 ldi r25, 0x03 ; 3
ee: 0e 94 f3 00 call 0x1e6 ; 0x1e6 <delay_ms>
green_led(1); // green LED on (will not work on the Baby Orangutan)
f2: 81 e0 ldi r24, 0x01 ; 1
f4: 0e 94 9d 00 call 0x13a ; 0x13a <green_led>
delay_ms(500); // waits for 0.5 seconds
f8: 84 ef ldi r24, 0xF4 ; 244
fa: 91 e0 ldi r25, 0x01 ; 1
fc: 0e 94 f3 00 call 0x1e6 ; 0x1e6 <delay_ms>
green_led(0); // green LED off (will not work on the Baby Orangutan)
100: 80 e0 ldi r24, 0x00 ; 0
102: 0e 94 9d 00 call 0x13a ; 0x13a <green_led>
delay_ms(500); // waits for 0.5 seconds
106: 84 ef ldi r24, 0xF4 ; 244
108: 91 e0 ldi r25, 0x01 ; 1
10a: 0e 94 f3 00 call 0x1e6 ; 0x1e6 <delay_ms>
10e: e3 cf rjmp .-58 ; 0xd6 <main+0x8>
00000110 <left_led>:
110: 3c 9a sbi 0x07, 4 ; 7
112: 88 23 and r24, r24
114: 11 f0 breq .+4 ; 0x11a <left_led+0xa>
116: 44 9a sbi 0x08, 4 ; 8
118: 08 95 ret
11a: 44 98 cbi 0x08, 4 ; 8
11c: 08 95 ret
0000011e <right_led>:
11e: 51 9a sbi 0x0a, 1 ; 10
120: 88 23 and r24, r24
122: 11 f0 breq .+4 ; 0x128 <right_led+0xa>
124: 59 98 cbi 0x0b, 1 ; 11
126: 08 95 ret
128: 59 9a sbi 0x0b, 1 ; 11
12a: 08 95 ret
0000012c <red_led>:
12c: 51 9a sbi 0x0a, 1 ; 10
12e: 88 23 and r24, r24
130: 11 f0 breq .+4 ; 0x136 <red_led+0xa>
132: 59 98 cbi 0x0b, 1 ; 11
134: 08 95 ret
136: 59 9a sbi 0x0b, 1 ; 11
138: 08 95 ret
0000013a <green_led>:
13a: 3c 9a sbi 0x07, 4 ; 7
13c: 88 23 and r24, r24
13e: 11 f0 breq .+4 ; 0x144 <green_led+0xa>
140: 44 9a sbi 0x08, 4 ; 8
142: 08 95 ret
144: 44 98 cbi 0x08, 4 ; 8
146: 08 95 ret
00000148 <_ZN13OrangutanLEDsC2Ev>:
148: 08 95 ret
0000014a <_ZN13OrangutanLEDsC1Ev>:
14a: 08 95 ret
0000014c <_ZN13OrangutanLEDs3redEh>:
14c: 51 9a sbi 0x0a, 1 ; 10
14e: 88 23 and r24, r24
150: 11 f0 breq .+4 ; 0x156 <_ZN13OrangutanLEDs3redEh+0xa>
152: 59 98 cbi 0x0b, 1 ; 11
154: 08 95 ret
156: 59 9a sbi 0x0b, 1 ; 11
158: 08 95 ret
0000015a <_ZN13OrangutanLEDs5greenEh>:
15a: 3c 9a sbi 0x07, 4 ; 7
15c: 88 23 and r24, r24
15e: 11 f0 breq .+4 ; 0x164 <_ZN13OrangutanLEDs5greenEh+0xa>
160: 44 9a sbi 0x08, 4 ; 8
162: 08 95 ret
164: 44 98 cbi 0x08, 4 ; 8
166: 08 95 ret
00000168 <__vector_11>:
168: 1f 92 push r1
16a: 0f 92 push r0
16c: 0f b6 in r0, 0x3f ; 63
16e: 0f 92 push r0
170: 11 24 eor r1, r1
172: 2f 93 push r18
174: 3f 93 push r19
176: 4f 93 push r20
178: 8f 93 push r24
17a: 9f 93 push r25
17c: af 93 push r26
17e: bf 93 push r27
180: 20 91 04 01 lds r18, 0x0104
184: 30 91 05 01 lds r19, 0x0105
188: c9 01 movw r24, r18
18a: 80 50 subi r24, 0x00 ; 0
18c: 9c 4f sbci r25, 0xFC ; 252
18e: 90 93 05 01 sts 0x0105, r25
192: 80 93 04 01 sts 0x0104, r24
196: 80 51 subi r24, 0x10 ; 16
198: 97 42 sbci r25, 0x27 ; 39
19a: c8 f0 brcs .+50 ; 0x1ce <__vector_11+0x66>
19c: 80 91 00 01 lds r24, 0x0100
1a0: 90 91 01 01 lds r25, 0x0101
1a4: a0 91 02 01 lds r26, 0x0102
1a8: b0 91 03 01 lds r27, 0x0103
1ac: 01 96 adiw r24, 0x01 ; 1
1ae: a1 1d adc r26, r1
1b0: b1 1d adc r27, r1
1b2: 80 93 00 01 sts 0x0100, r24
1b6: 90 93 01 01 sts 0x0101, r25
1ba: a0 93 02 01 sts 0x0102, r26
1be: b0 93 03 01 sts 0x0103, r27
1c2: 20 51 subi r18, 0x10 ; 16
1c4: 33 42 sbci r19, 0x23 ; 35
1c6: 30 93 05 01 sts 0x0105, r19
1ca: 20 93 04 01 sts 0x0104, r18
1ce: bf 91 pop r27
1d0: af 91 pop r26
1d2: 9f 91 pop r25
1d4: 8f 91 pop r24
1d6: 4f 91 pop r20
1d8: 3f 91 pop r19
1da: 2f 91 pop r18
1dc: 0f 90 pop r0
1de: 0f be out 0x3f, r0 ; 63
1e0: 0f 90 pop r0
1e2: 1f 90 pop r1
1e4: 18 95 reti
000001e6 <delay_ms>:
1e6: 28 ee ldi r18, 0xE8 ; 232
1e8: 33 e0 ldi r19, 0x03 ; 3
1ea: 09 c0 rjmp .+18 ; 0x1fe <delay_ms+0x18>
1ec: f9 01 movw r30, r18
1ee: 6f 93 push r22
1f0: 64 e0 ldi r22, 0x04 ; 4
1f2: 6a 95 dec r22
1f4: f1 f7 brne .-4 ; 0x1f2 <delay_ms+0xc>
1f6: 6f 91 pop r22
1f8: 31 97 sbiw r30, 0x01 ; 1
1fa: c9 f7 brne .-14 ; 0x1ee <delay_ms+0x8>
1fc: 01 97 sbiw r24, 0x01 ; 1
1fe: 00 97 sbiw r24, 0x00 ; 0
200: a9 f7 brne .-22 ; 0x1ec <delay_ms+0x6>
202: 08 95 ret
00000204 <_ZN13OrangutanTime17delayMillisecondsEj>:
204: 28 ee ldi r18, 0xE8 ; 232
206: 33 e0 ldi r19, 0x03 ; 3
208: 09 c0 rjmp .+18 ; 0x21c <_ZN13OrangutanTime17delayMillisecondsEj+0x18>
20a: f9 01 movw r30, r18
20c: 6f 93 push r22
20e: 64 e0 ldi r22, 0x04 ; 4
210: 6a 95 dec r22
212: f1 f7 brne .-4 ; 0x210 <_ZN13OrangutanTime17delayMillisecondsEj+0xc>
214: 6f 91 pop r22
216: 31 97 sbiw r30, 0x01 ; 1
218: c9 f7 brne .-14 ; 0x20c <_ZN13OrangutanTime17delayMillisecondsEj+0x8>
21a: 01 97 sbiw r24, 0x01 ; 1
21c: 00 97 sbiw r24, 0x00 ; 0
21e: a9 f7 brne .-22 ; 0x20a <_ZN13OrangutanTime17delayMillisecondsEj+0x6>
220: 08 95 ret
00000222 <_ZN13OrangutanTime5init2Ev>:
222: a0 e7 ldi r26, 0x70 ; 112
224: b0 e0 ldi r27, 0x00 ; 0
226: 8c 91 ld r24, X
228: 8e 7f andi r24, 0xFE ; 254
22a: 8c 93 st X, r24
22c: e0 eb ldi r30, 0xB0 ; 176
22e: f0 e0 ldi r31, 0x00 ; 0
230: 80 81 ld r24, Z
232: 83 60 ori r24, 0x03 ; 3
234: 80 83 st Z, r24
236: e1 eb ldi r30, 0xB1 ; 177
238: f0 e0 ldi r31, 0x00 ; 0
23a: 80 81 ld r24, Z
23c: 80 7f andi r24, 0xF0 ; 240
23e: 80 83 st Z, r24
240: 80 81 ld r24, Z
242: 82 60 ori r24, 0x02 ; 2
244: 80 83 st Z, r24
246: b8 9a sbi 0x17, 0 ; 23
248: 8c 91 ld r24, X
24a: 81 60 ori r24, 0x01 ; 1
24c: 8c 93 st X, r24
24e: 78 94 sei
250: 08 95 ret
00000252 <_ZN13OrangutanTime4initEv>:
252: 80 91 06 01 lds r24, 0x0106
256: 88 23 and r24, r24
258: 29 f4 brne .+10 ; 0x264 <_ZN13OrangutanTime4initEv+0x12>
25a: 81 e0 ldi r24, 0x01 ; 1
25c: 80 93 06 01 sts 0x0106, r24
260: 0e 94 11 01 call 0x222 ; 0x222 <_ZN13OrangutanTime5init2Ev>
264: 08 95 ret
00000266 <_ZN13OrangutanTime2msEv>:
266: 0e 94 29 01 call 0x252 ; 0x252 <_ZN13OrangutanTime4initEv>
26a: e0 e7 ldi r30, 0x70 ; 112
26c: f0 e0 ldi r31, 0x00 ; 0
26e: 80 81 ld r24, Z
270: 8e 7f andi r24, 0xFE ; 254
272: 80 83 st Z, r24
274: 20 91 00 01 lds r18, 0x0100
278: 30 91 01 01 lds r19, 0x0101
27c: 40 91 02 01 lds r20, 0x0102
280: 50 91 03 01 lds r21, 0x0103
284: 80 81 ld r24, Z
286: 81 60 ori r24, 0x01 ; 1
288: 80 83 st Z, r24
28a: b9 01 movw r22, r18
28c: ca 01 movw r24, r20
28e: 08 95 ret
00000290 <get_ms>:
290: 0e 94 33 01 call 0x266 ; 0x266 <_ZN13OrangutanTime2msEv>
294: 08 95 ret
00000296 <_ZN13OrangutanTime5resetEv>:
296: 0e 94 29 01 call 0x252 ; 0x252 <_ZN13OrangutanTime4initEv>
29a: e0 e7 ldi r30, 0x70 ; 112
29c: f0 e0 ldi r31, 0x00 ; 0
29e: 80 81 ld r24, Z
2a0: 8e 7f andi r24, 0xFE ; 254
2a2: 80 83 st Z, r24
2a4: 10 92 00 01 sts 0x0100, r1
2a8: 10 92 01 01 sts 0x0101, r1
2ac: 10 92 02 01 sts 0x0102, r1
2b0: 10 92 03 01 sts 0x0103, r1
2b4: 10 92 05 01 sts 0x0105, r1
2b8: 10 92 04 01 sts 0x0104, r1
2bc: b8 9a sbi 0x17, 0 ; 23
2be: 80 81 ld r24, Z
2c0: 81 60 ori r24, 0x01 ; 1
2c2: 80 83 st Z, r24
2c4: 08 95 ret
000002c6 <time_reset>:
2c6: 0e 94 4b 01 call 0x296 ; 0x296 <_ZN13OrangutanTime5resetEv>
2ca: 08 95 ret
000002cc <_exit>:
2cc: f8 94 cli
000002ce <__stop_program>:
2ce: ff cf rjmp .-2 ; 0x2ce <__stop_program>