Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 March 5, 2008 02:47:31

A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] PORTC


Hi,


I have a program for atmega8 and the program is working well when I compile it
using WinAVR-20040404-bin-install.exe.
But when I compile it using WinAVR-20071221-install.exe the program isn't
working anymore.
And I found something, the compiler didn't the code to set and clear PORTC.
I had tried using PORTC |= (1<<n) and PORTC &= ~(1<<n) but still the compiler
won't compile it.

Is it a bug ? Or , do I miss something ?


Andi_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#2 March 5, 2008 03:26:31

Paulo M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] PORTC


Quoting Andi <>:Hi,Hi,I have a program for atmega8 and the program is working well when Icompile it using WinAVR-20040404-bin-install.exe.But when I compile it using WinAVR-20071221-install.exe the programisn't working anymore.And I found something, the compiler didn't the code to set and clear PORTC.I had tried using PORTC |= (1<<n) and PORTC &= ~(1<<n) but still thecompiler won't compile it.Is it a bug ? Or , do I miss something ?It is hard to tell without knowing the rest of the code. If thatsnippet is in a static function that is not called from anywhere, thecompiler is free to just drop it. Preferably provide a compilable smallexample, so that others can compile the same test and see what is goingon.--
Paulo Marques


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#3 March 5, 2008 04:10:06

A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] PORTC


This is the code:

#define sbi(PORT,BIT) (PORT |= (1<<BIT))
#define cbi(PORT,BIT) (PORT &= ~(1<<BIT))
#define ToPABX sbi(PORTC,1)
#define ExitPABX cbi(PORTC,1)
#define LoadToLine sbi(PORTC,2)
#define LoadOff cbi(PORTC,2)
#define PABXPowerOn sbi(PORTD,4)
#define PABXPowerOff cbi(PORTD,4)

void InitLoad(void)
{
sbi(DDRC,2);
LoadOff;
}

void InitPABX(void)
{
sbi(DDRC,1);
sbi(DDRD,4);
ExitPABX;
PABXPowerOff;
}

the LST generated file:

992:voip.c **** void InitLoad(void)
993:voip.c **** {
1384 ,1000,.LM218-InitPABX
1385 .LM218:
1386 sbi 52-0x20,1
994:voip.c **** sbi(DDRC,2);
1388 19:
1389 sbi 49-0x20,4
995:voip.c **** LoadOff;
1391 220:
1392 cbi 53-0x20,1
1394 .LM221:
1395 0358 0895 cbi 50-0x20,4
1396 /* epilogue: frame size=0 */
1397 ret
1398 /* epilogue end (size=1) */
1399 /* function InitPABX size 5 (4) */
1401 .Lscope32:
1403 .global InitIndicator
996:voip.c **** }
997:voip.c ****
998:voip.c **** void InitPABX(void)
999:voip.c **** {
1404 dicator, @function
1405 InitIndicator:
1407 .LM222:
1000:voip.c **** sbi(DDRC,1);
1408 rologue: frame size=0 */
1409 /* prologue end (size=0) */
1001:voip.c **** sbi(DDRD,4);
1411 223:
1412 sbi 49-0x20,0
1002:voip.c **** ExitPABX;
1414 224:
1415 sbi 50-0x20,0
1416 035e A998 /* epilogue: frame size=0 */
1003:voip.c **** PABXPowerOff;
1417 t
1418 /* epilogue end (size=1) */
1419 0360 9498 /* function InitIndicator size 3 (2) */
1421 0362 0895 .Lscope33:
1423 .global __vector_2
1425 __vector_2:
1427 .LM225:
1428 /* prologue: frame size=0 */
1429 push __zero_reg__
1004:voip.c **** }
1005:voip.c ****


Andi----- Original Message -----From: "Paulo Marques" <>To: "Andi" <>
Cc: <avr-gcc-l***@*ongnu.org>
Sent: Wednesday, March 05, 2008 11:06 AM
Subject: Re: PORTCQuoting Andi <>:Hi,Hi,I have a program for atmega8 and the program is working well when Icompile it using WinAVR-20040404-bin-install.exe.But when I compile it using WinAVR-20071221-install.exe the programisn't working anymore.And I found something, the compiler didn't the code to set and clearPORTC.I had tried using PORTC |= (1<<n) and PORTC &= ~(1<<n) but still thecompiler won't compile it.Is it a bug ? Or , do I miss something ?It is hard to tell without knowing the rest of the code. If that snippetis in a static function that is not called from anywhere, the compiler isfree to just drop it. Preferably provide a compilable small example, sothat others can compile the same test and see what is going on.--
Paulo Marques


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program._______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#4 March 10, 2008 21:32:18

Joerg W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] PORTC


"Andi" <> wrote:

> This is the code:

Sending compilable code makes us better trust you not doing any
copy&paste errors. Let's hope all that you left out is the #include
<avr/io.h>.

> the LST generated file:

I never understand why people are so fond of that unreadable
disassembly stuff. It also appears your copy&paste left out some
single letters there.

Here's the assembly code the compiler generates when I add the
<avr/io.h> include line, and compile it for an ATmega8 with -Os:

..global InitLoad
.type InitLoad, @function
InitLoad:
/* prologue: frame size=0 */
/* prologue end (size=0) */
sbi 52-0x20,2
cbi 53-0x20,2
/* epilogue: frame size=0 */
ret
/* epilogue end (size=1) */
/* function InitLoad size 3 (2) */
.size InitLoad, .-InitLoad
..global InitPABX
.type InitPABX, @function
InitPABX:
/* prologue: frame size=0 */
/* prologue end (size=0) */
sbi 52-0x20,1
sbi 49-0x20,4
cbi 53-0x20,1
cbi 50-0x20,4
/* epilogue: frame size=0 */
ret
/* epilogue end (size=1) */
/* function InitPABX size 5 (4) */

That looks pretty fine to me. If I compile it into a .o file, and
just disassemble it (without the annoying attempt to intersperse it
with what the disassembler believes were the related source code),
I get:

Disassembly of section .text:

00000000 <InitLoad>:
0: a2 9a sbi 0x14, 2 ; 20
2: aa 98 cbi 0x15, 2 ; 21
4: 08 95 ret

00000006 <InitPABX>:
6: a1 9a sbi 0x14, 1 ; 20
8: 8c 9a sbi 0x11, 4 ; 17
a: a9 98 cbi 0x15, 1 ; 21
c: 94 98 cbi 0x12, 4 ; 18
e: 08 95 ret

Again, all looks fine to me.

--
cheers, J"org .-.-. --... ...-- -.. . DL8DTLhttp://www.sax.de/~joerg/NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#5 March 11, 2008 04:00:03

A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] PORTC


Hi Joerg,I didn't missed to add #include <avr/io.h> in my file. Sorry I didn'tattach the all code because it's too long.I have no problem before when I compile with WinAVR2004 and WinAVR2005, thisonly happen with WinAVR2007 where the compiler can generate sbi and cbicommand for PORTC (no problem for the other ports)I'm still checking where is the problem now.

Thanks,
Regards

Andi----- Original Message -----From: "Joerg Wunsch" <>To: <avr-gcc-l***@*ongnu.org>
Sent: Tuesday, March 11, 2008 3:32 AM
Subject: Re: PORTC"Andi" <> wrote:This is the code:Sending compilable code makes us better trust you not doing any
copy&paste errors. Let's hope all that you left out is the #include
<avr/io.h>.the LST generated file:I never understand why people are so fond of that unreadable
disassembly stuff. It also appears your copy&paste left out some
single letters there.

Here's the assembly code the compiler generates when I add the
<avr/io.h> include line, and compile it for an ATmega8 with -Os:

..global InitLoad
.type InitLoad, @function
InitLoad:
/* prologue: frame size=0 */
/* prologue end (size=0) */
sbi 52-0x20,2
cbi 53-0x20,2
/* epilogue: frame size=0 */
ret
/* epilogue end (size=1) */
/* function InitLoad size 3 (2) */
.size InitLoad, .-InitLoad
..global InitPABX
.type InitPABX, @function
InitPABX:
/* prologue: frame size=0 */
/* prologue end (size=0) */
sbi 52-0x20,1
sbi 49-0x20,4
cbi 53-0x20,1
cbi 50-0x20,4
/* epilogue: frame size=0 */
ret
/* epilogue end (size=1) */
/* function InitPABX size 5 (4) */

That looks pretty fine to me. If I compile it into a .o file, and
just disassemble it (without the annoying attempt to intersperse it
with what the disassembler believes were the related source code),
I get:

Disassembly of section .text:

00000000 <InitLoad>:
0: a2 9a sbi 0x14, 2 ; 20
2: aa 98 cbi 0x15, 2 ; 21
4: 08 95 ret

00000006 <InitPABX>:
6: a1 9a sbi 0x14, 1 ; 20
8: 8c 9a sbi 0x11, 4 ; 17
a: a9 98 cbi 0x15, 1 ; 21
c: 94 98 cbi 0x12, 4 ; 18
e: 08 95 ret

Again, all looks fine to me.

--
cheers, J"org .-.-. --... ...-- -.. . DL8DTLhttp://www.sax.de/~joerg/NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-l***@*ongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#6 March 11, 2008 20:23:48

Joerg W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] PORTC


"Andi" <> wrote:

> I have no problem before when I compile with WinAVR2004 and
> WinAVR2005, this only happen with WinAVR2007 where the compiler can
> generate sbi and cbi command for PORTC (no problem for the other
> ports)

The compiler *is* generating the IO instructions for port C correctly.
Of course, you should never say never, but there's a much higher
probability that you win next week's lotto jackpot than there would be
that the compiler failed to generate that simple kind of IO
instruction code, and you were the first to detect it.

> I'm still checking where is the problem now.

Elsewhere. Don't be fooled by viewing the disassembly listing with
the interspersed C code. Look at a plain disassembly or the generated
assembly code instead. In my opinion, these diassembly + source code
list files are much more obfuscating the view rather than clarifying
anything (even more, the more clever the compiler's optimizations are
getting).

Since you upgraded from a really old version of the compiler, my first
guess would be that you've been trapped by trying to invent your own
delay loops, which are now completely eliminated by the compiler.

--
cheers, J"org .-.-. --... ...-- -.. . DL8DTLhttp://www.sax.de/~joerg/NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#7 March 11, 2008 21:38:13

David K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] PORTC


On Tue, Mar 11, 2008 at 08:22:23PM +0100, Joerg Wunsch wrote:
> "Andi" <> wrote:
>
> > I'm still checking where is the problem now.
>
> Elsewhere. Don't be fooled by viewing the disassembly listing with
> the interspersed C code. Look at a plain disassembly or the generated
> assembly code instead. In my opinion, these diassembly + source code
> list files are much more obfuscating the view rather than clarifying
> anything (even more, the more clever the compiler's optimizations are
> getting).

Or set a breakpoint prior to the PORTC code, run to break, "View
Disassembly" in AVR Studio and then single step through the code. This
is the best way I can think of to be sure one is looking at the real
code generated by the compiler.

I do generate a list file from elf and source in my Makefile because its
often useful. But as Joerg points out it has to be used with a big dose
of distrust. Code sections disassemble quite well but if there is much
else in the file such as constant data then the same "section of code"
may be "disassembled" several times.

"avr-objdump -dS" usually produces very good output. "-DS" does the same
as -dS plus a whole bunch of crap disassembled where its not code. At
least when one uses -O2 to compile.

--
David Kelly N4HHE,
========================================================================
Whom computers would destroy, they must first drive mad.


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#8 March 12, 2008 03:03:57

A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] PORTC


I had test the code in AVR Studio, and the AVR Studio didn't execute thecommand :(. It jump to the next code. So, it look like the compiler didn'tcompile the code.Andi----- Original Message -----From: "David Kelly" <>To: <avr-gcc-l***@*ongnu.org>
Sent: Wednesday, March 12, 2008 3:36 AM
Subject: Re: PORTCOn Tue, Mar 11, 2008 at 08:22:23PM +0100, Joerg Wunsch wrote:"Andi" <> wrote:

> I'm still checking where is the problem now.

Elsewhere. Don't be fooled by viewing the disassembly listing with
the interspersed C code. Look at a plain disassembly or the generated
assembly code instead. In my opinion, these diassembly + source code
list files are much more obfuscating the view rather than clarifying
anything (even more, the more clever the compiler's optimizations are
getting).Or set a breakpoint prior to the PORTC code, run to break, "View
Disassembly" in AVR Studio and then single step through the code. This
is the best way I can think of to be sure one is looking at the real
code generated by the compiler.

I do generate a list file from elf and source in my Makefile because its
often useful. But as Joerg points out it has to be used with a big dose
of distrust. Code sections disassemble quite well but if there is much
else in the file such as constant data then the same "section of code"
may be "disassembled" several times.

"avr-objdump -dS" usually produces very good output. "-DS" does the same
as -dS plus a whole bunch of crap disassembled where its not code. At
least when one uses -O2 to compile.

--
David Kelly N4HHE,
========================================================================
Whom computers would destroy, they must first drive mad.


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-l***@*ongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#9 March 12, 2008 22:07:29

Joerg W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] PORTC


"Andi" <> wrote:

> So, it look like the compiler didn't
> compile the code.

The compiler will only omit your code if it's known at
compile-time that it cannot be reached at all.

Compilers are stupid, but they are following a set of
well-established rules called the C standard. They simply
do what you are telling them to do.

--
cheers, J"org .-.-. --... ...-- -.. . DL8DTLhttp://www.sax.de/~joerg/NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

Board footer

Moderator control

Enjoy the 16th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support