> -----Original Message----- > From: > [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > org] On Behalf Of Dmitry K. > Sent: Tuesday, March 06, 2007 7:31 PM > To: [email protected] > Subject: Re: [avr-gcc-list] Endless loop: uchar c; for (c=1; c; c++) > > On Wednesday 07 March 2007 04:10, Eric Weddington wrote: > [...] > > It seems that when compiling to assembler (-S as Dmitry > recommends above), > > then you'll note that the epilogue is set to noreturn, > which also ends up > > taking out the final breq of the outer loop, as there is > nothing to branch > > to anymore. > > > > However, when I compile and assemble, and I look at a > requested listing > > from the assembler (basically using the WinAVR Makefile > Template), the code > > looks fine. An epilog exists, and the correct end condition > for the loop is > > in the code. This is also the case when I do a disassembly > on the object > > code (avr-objdump -d <object>); the code looks fine, an > epilog exists, and > > the branch is in the code. > > > > Does anyone have an idea why using avr-gcc -S ... would be > so different > > then the actual code generated (as compared to the disassembly)? > > I try to compile without `-S' option: result is the same.
Going back to your original code, see the resulting attached files: bug.lst - The assembler listing after compiling and assembling bug.dis - The disassembled output from avr-objdump -d bug.o These files are generated with avr-gcc 4.1.1 and using -Os. I still don't see a bug where it goes into an infinite loop. To me it looks like that it will eventually break out of the outer loop. Eric
1 .file "bug.c"
2 .arch atmega128
3 __SREG__ = 0x3f
4 __SP_H__ = 0x3e
5 __SP_L__ = 0x3d
6 __tmp_reg__ = 0
7 __zero_reg__ = 1
8 .global __do_copy_data
9 .global __do_clear_bss
17 .Ltext0:
18 .data
19 .LC0:
20 0000 2E00 .string "."
21 .text
22 .global main
24 main:
25 .LFB2:
26 .LM1:
27 /* prologue: frame size=4 */
28 0000 0F93 push r16
29 0002 1F93 push r17
30 0004 CF93 push r28
31 0006 DF93 push r29
32 0008 CDB7 in r28,__SP_L__
33 000a DEB7 in r29,__SP_H__
34 000c 2497 sbiw r28,4
35 000e 0FB6 in __tmp_reg__,__SREG__
36 0010 F894 cli
37 0012 DEBF out __SP_H__,r29
38 0014 0FBE out __SREG__,__tmp_reg__
39 0016 CDBF out __SP_L__,r28
40 /* prologue end (size=12) */
41 .LM2:
42 0018 8091 0000 lds r24,.LC0
43 001c 9091 0000 lds r25,(.LC0)+1
44 0020 9C83 std Y+4,r25
45 0022 8B83 std Y+3,r24
46 .LVL0:
47 .LM3:
48 0024 9A83 std Y+2,r25
49 0026 8983 std Y+1,r24
50 .LVL1:
51 0028 01E0 ldi r16,lo8(1)
52 .LVL2:
53 002a 00C0 rjmp .L2
54 .LVL3:
55 .L3:
56 .LM4:
57 002c 0B83 std Y+3,r16
58 .LM5:
59 002e 1983 std Y+1,r17
60 .LM6:
61 0030 BE01 movw r22,r28
62 0032 6F5F subi r22,lo8(-(1))
63 0034 7F4F sbci r23,hi8(-(1))
64 0036 CE01 movw r24,r28
65 0038 0396 adiw r24,3
66 003a 0E94 0000 call foo
67 .LM7:
68 003e 1F5F subi r17,lo8(-(1))
69 0040 01F4 brne .L3
70 .LM8:
71 0042 0F5F subi r16,lo8(-(1))
72 0044 01F0 breq .L7
73 .LVL4:
74 .L2:
75 0046 11E0 ldi r17,lo8(1)
76 0048 00C0 rjmp .L3
77 .LVL5:
78 .L7:
79 .LM9:
80 004a 80E0 ldi r24,lo8(0)
81 004c 90E0 ldi r25,hi8(0)
82 /* epilogue: frame size=4 */
83 004e 2496 adiw r28,4
84 0050 0FB6 in __tmp_reg__,__SREG__
85 0052 F894 cli
86 0054 DEBF out __SP_H__,r29
87 0056 0FBE out __SREG__,__tmp_reg__
88 0058 CDBF out __SP_L__,r28
89 005a DF91 pop r29
90 005c CF91 pop r28
91 005e 1F91 pop r17
92 0060 0F91 pop r16
93 0062 0895 ret
94 /* epilogue end (size=11) */
95 /* function main size 52 (29) */
96 .LFE2:
120 .Letext0:
DEFINED SYMBOLS
*ABS*:00000000 bug.c
C:\DOCUME~1\EWEDDI~1\LOCALS~1\Temp/ccWKaaaa.s:3 *ABS*:0000003f __SREG__
C:\DOCUME~1\EWEDDI~1\LOCALS~1\Temp/ccWKaaaa.s:4 *ABS*:0000003e __SP_H__
C:\DOCUME~1\EWEDDI~1\LOCALS~1\Temp/ccWKaaaa.s:5 *ABS*:0000003d __SP_L__
C:\DOCUME~1\EWEDDI~1\LOCALS~1\Temp/ccWKaaaa.s:6 *ABS*:00000000 __tmp_reg__
C:\DOCUME~1\EWEDDI~1\LOCALS~1\Temp/ccWKaaaa.s:7 *ABS*:00000001 __zero_reg__
C:\DOCUME~1\EWEDDI~1\LOCALS~1\Temp/ccWKaaaa.s:24 .text:00000000 main
UNDEFINED SYMBOLS
__do_copy_data
__do_clear_bss
foo
bug.dis
Description: Binary data
_______________________________________________ AVR-GCC-list mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
