[Top][All Lists]

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

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

From: Zane D. Purvis
Subject: Re: [avr-gcc-list] Bug or bad optimization?
Date: Wed, 02 Mar 2005 11:54:25 -0500
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

Make sure you've declared command as "volatile":

volatile unsigned char command;

That will tell the compiler to reload it from memory every time it is read.

Jim Davis wrote:

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;
                command = NULL;
                while(command == NULL);
                        // wait for command in uart getchar
                if (command == CR)

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

reply via email to

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