[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Endless loop: uchar c; for (c=1; c; c++)
From: |
Bob Paddock |
Subject: |
Re: [avr-gcc-list] Endless loop: uchar c; for (c=1; c; c++) |
Date: |
Wed, 07 Mar 2007 09:36:09 -0500 |
User-agent: |
Opera Mail/9.10 (Win32) |
On Tue, 06 Mar 2007 21:31:09 -0500, Dmitry K. <address@hidden>
wrote:
My results for 3.4.5 and 4.1.1 for the follow program, below:
Program:
~~~~~~~
/* This program is compiled as endless loop: condition `c1 != 0'
is not tested. In original (real) program there was an another
error: in conditional expression based on c1 and c2 inside the
loops (here this is removed).
Compiler: avr-gcc 4.1.1
Options: -W -Wall -Os */
void exit (int);
void foo (const char *s1, const char *s2)
{
static unsigned char n;
if ((*s1 == 1) && (*s2 == 1)) {
/* The big number 10 is to enlarge a simulation time, number 1
is sufficient to demonstrate an error. */
if (++n > 10)
exit (n);
}
}
int main ()
{
unsigned char c1, c2;
char s1[2] = ".";
char s2[2] = ".";
for (c1 = 1; c1; c1++) {
for (c2 = 1; c2; c2++) {
s1[0] = c1;
s2[0] = c2;
foo (s1, s2);
}
}
return 0;
}
Disassemble:
WinAVR-20070121, mfile generated Makefile,
code as above:
000000ce <foo>:
void foo (const char *s1, const char *s2);
void foo (const char *s1, const char *s2)
{
ce: fc 01 movw r30, r24
d0: db 01 movw r26, r22
static unsigned char n;
if ((*s1 == 1) && (*s2 == 1)) {
d2: 80 81 ld r24, Z
d4: 81 30 cpi r24, 0x01 ; 1
d6: 69 f4 brne .+26 ; 0xf2 <foo+0x24>
d8: 8c 91 ld r24, X
da: 81 30 cpi r24, 0x01 ; 1
dc: 51 f4 brne .+20 ; 0xf2 <foo+0x24>
/* The big number 10 is to enlarge a simulation time, number 1
is sufficient to demonstrate an error. */
if (++n > 10)
de: 80 91 02 01 lds r24, 0x0102
e2: 8f 5f subi r24, 0xFF ; 255
e4: 80 93 02 01 sts 0x0102, r24
e8: 8b 30 cpi r24, 0x0B ; 11
ea: 18 f0 brcs .+6 ; 0xf2 <foo+0x24>
exit (n);
ec: 99 27 eor r25, r25
ee: 0e 94 ac 00 call 0x158 ; 0x158 <_exit>
f2: 08 95 ret
000000f4 <main>:
}
}
int main ()
{
f4: 0f 93 push r16
f6: 1f 93 push r17
f8: cf 93 push r28
fa: df 93 push r29
fc: cd b7 in r28, 0x3d ; 61
fe: de b7 in r29, 0x3e ; 62
100: 24 97 sbiw r28, 0x04 ; 4
102: 0f b6 in r0, 0x3f ; 63
104: f8 94 cli
106: de bf out 0x3e, r29 ; 62
108: 0f be out 0x3f, r0 ; 63
10a: cd bf out 0x3d, r28 ; 61
unsigned char c1, c2;
char s1[2] = ".";
10c: 80 91 00 01 lds r24, 0x0100
110: 90 91 01 01 lds r25, 0x0101
114: 9c 83 std Y+4, r25 ; 0x04
116: 8b 83 std Y+3, r24 ; 0x03
char s2[2] = ".";
118: 9a 83 std Y+2, r25 ; 0x02
11a: 89 83 std Y+1, r24 ; 0x01
11c: 01 e0 ldi r16, 0x01 ; 1
11e: 0d c0 rjmp .+26 ; 0x13a <main+0x46>
for (c1 = 1; c1; c1++) {
for (c2 = 1; c2; c2++) {
s1[0] = c1;
120: 0b 83 std Y+3, r16 ; 0x03
s2[0] = c2;
122: 19 83 std Y+1, r17 ; 0x01
foo (s1, s2);
124: be 01 movw r22, r28
126: 6f 5f subi r22, 0xFF ; 255
128: 7f 4f sbci r23, 0xFF ; 255
12a: ce 01 movw r24, r28
12c: 03 96 adiw r24, 0x03 ; 3
12e: 0e 94 67 00 call 0xce ; 0xce <foo>
132: 1f 5f subi r17, 0xFF ; 255
134: a9 f7 brne .-22 ; 0x120 <main+0x2c>
136: 0f 5f subi r16, 0xFF ; 255
138: 11 f0 breq .+4 ; 0x13e <main+0x4a>
13a: 11 e0 ldi r17, 0x01 ; 1
13c: f1 cf rjmp .-30 ; 0x120 <main+0x2c>
}
}
return 0;
}
13e: 80 e0 ldi r24, 0x00 ; 0
140: 90 e0 ldi r25, 0x00 ; 0
142: 24 96 adiw r28, 0x04 ; 4
144: 0f b6 in r0, 0x3f ; 63
146: f8 94 cli
148: de bf out 0x3e, r29 ; 62
14a: 0f be out 0x3f, r0 ; 63
14c: cd bf out 0x3d, r28 ; 61
14e: df 91 pop r29
150: cf 91 pop r28
152: 1f 91 pop r17
154: 0f 91 pop r16
156: 08 95 ret
00000158 <_exit>:
158: ff cf rjmp .-2 ; 0x158 <_exit>
3.4.5, same Makefile, same code:
000000ce <foo>:
void foo (const char *s1, const char *s2);
void foo (const char *s1, const char *s2)
{
ce: fc 01 movw r30, r24
d0: db 01 movw r26, r22
static unsigned char n;
if ((*s1 == 1) && (*s2 == 1)) {
d2: 80 81 ld r24, Z
d4: 81 30 cpi r24, 0x01 ; 1
d6: 69 f4 brne .+26 ; 0xf2 <foo+0x24>
d8: 8c 91 ld r24, X
da: 81 30 cpi r24, 0x01 ; 1
dc: 51 f4 brne .+20 ; 0xf2 <foo+0x24>
/* The big number 10 is to enlarge a simulation time, number 1
is sufficient to demonstrate an error. */
if (++n > 10)
de: 80 91 02 01 lds r24, 0x0102
e2: 8f 5f subi r24, 0xFF ; 255
e4: 80 93 02 01 sts 0x0102, r24
e8: 8b 30 cpi r24, 0x0B ; 11
ea: 18 f0 brcs .+6 ; 0xf2 <foo+0x24>
exit (n);
ec: 99 27 eor r25, r25
ee: 0e 94 99 00 call 0x132 <_exit>
f2: 08 95 ret
000000f4 <main>:
}
}
int main ()
{
f4: cb ef ldi r28, 0xFB ; 251
f6: d0 e1 ldi r29, 0x10 ; 16
f8: de bf out 0x3e, r29 ; 62
fa: cd bf out 0x3d, r28 ; 61
unsigned char c1, c2;
char s1[2] = ".";
fc: 80 91 00 01 lds r24, 0x0100
100: 90 91 01 01 lds r25, 0x0101
104: 9c 83 std Y+4, r25 ; 0x04
106: 8b 83 std Y+3, r24 ; 0x03
char s2[2] = ".";
108: 9a 83 std Y+2, r25 ; 0x02
10a: 89 83 std Y+1, r24 ; 0x01
for (c1 = 1; c1; c1++) {
10c: 01 e0 ldi r16, 0x01 ; 1
for (c2 = 1; c2; c2++) {
10e: 11 e0 ldi r17, 0x01 ; 1
s1[0] = c1;
110: 0b 83 std Y+3, r16 ; 0x03
s2[0] = c2;
112: 19 83 std Y+1, r17 ; 0x01
foo (s1, s2);
114: be 01 movw r22, r28
116: 6f 5f subi r22, 0xFF ; 255
118: 7f 4f sbci r23, 0xFF ; 255
11a: ce 01 movw r24, r28
11c: 03 96 adiw r24, 0x03 ; 3
11e: 0e 94 67 00 call 0xce <foo>
122: 1f 5f subi r17, 0xFF ; 255
124: a9 f7 brne .-22 ; 0x110 <main+0x1c>
126: 0f 5f subi r16, 0xFF ; 255
128: 91 f7 brne .-28 ; 0x10e <main+0x1a>
}
}
return 0;
}
12a: 80 e0 ldi r24, 0x00 ; 0
12c: 90 e0 ldi r25, 0x00 ; 0
12e: 0c 94 99 00 jmp 0x132 <_exit>
00000132 <_exit>:
132: ff cf rjmp .-2 ; 0x132 <_exit>
3.4.5 is 310 bytes, 4.1.1 is 348 bytes.
Re: [avr-gcc-list] Endless loop: uchar c; for (c=1; c; c++), Shaun Jackman, 2007/03/07