avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Bug or bad optimization?


From: Jim Davis
Subject: [avr-gcc-list] Bug or bad optimization?
Date: Wed, 2 Mar 2005 08:37:05 -0800

The following code generation has a problem handling
the external variable "command":

1) I dont see the global variable "command" has been put into r16
2) The while loop never loads r16 with the global before the test.

What is the proper way to tell the compiler what to do here?

------------------------------------------- C source
extern unsigned char command;
char *get_command(void)
{
        int i = 0;
        while(1)
        {
                command = NULL;
                while(command == NULL);
                        // wait for command in uart getchar
                if (command == CR)
---------------------------------------------
m   -----------------------------
80:       char *get_command(void)
81:       {
+00000962:   92EF        PUSH    R14              Push register on stack
+00000963:   92FF        PUSH    R15              Push register on stack
+00000964:   930F        PUSH    R16              Push register on stack
+00000965:   931F        PUSH    R17              Push register on stack
+00000966:   93CF        PUSH    R28              Push register on stack
+00000967:   93DF        PUSH    R29              Push register on stack
82:             int i = 0;
+00000968:   E0C0        LDI     R28,0x00         Load immediate
+00000969:   E0D0        LDI     R29,0x00         Load immediate
+0000096A:   E38E        LDI     R24,0x3E         Load immediate
+0000096B:   2EE8        MOV     R14,R24          Copy register
+0000096C:   E183        LDI     R24,0x13         Load immediate
+0000096D:   2EF8        MOV     R15,R24          Copy register
85:                     command = NULL;
+0000096E:   9210150E    STS     0x150E,R1        Store direct to data space
+00000970:   E000        LDI     R16,0x00         Load immediate
86:                     while(command == NULL);
+00000971:   2300        TST     R16              Test for Zero or Minus
+00000972:   F3F1        BREQ    PC-0x01          Branch if equal
88:                     if (command == CR)
+00000973:   300D        CPI     R16,0x0D         Compare with immediate
----------------------------------------------------------------------------
---

avr-gcc -S -mmcu=atmega128 -I. -gstabs   -Os -funsigned-char -funsigned-bitf
ields -fpack-struct -fshort-enums
-Wall -Wstrict-prototypes -Wa,-adhlns=toGui/main.lst -Ic:/machinetalker/inc 
-Ic:/winavr/avr/include -
Ic:/winavr/avr/include/avr -std=gnu89 -Wp,-M,-MP,-MT,main.o,-MF,.dep/main.s.
d toGui/main.c -o toGui/main.s





reply via email to

[Prev in Thread] Current Thread [Next in Thread]