This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C2000 Compiler v6.4.0: Compiler casting bug?

Guru 20035 points

Hello,

Please see below.   Shouldn't cc and dd have the same result? I have also tried casting to a signed long and compiler versions ,v6.4.1 and v6.2.10.

Stephen

C Code:

unsigned int xx = 65494; //=0xFFD6
signed int yy = -42; // = 0xFFD6

int main(void)
{
    unsigned long int cc = 0;
    unsigned long int dd = 0;

    cc = ((long)xx)*((long)xx); //cc = 4289464036
    dd = ((long)yy)*((long)yy); //dd = 1764

	return 0;
}

Assembly Code:

        main():
0000cb:   FE04        ADDB         SP, #4
12          unsigned long int cc = 0;
0000cc:   0200        MOVB         ACC, #0
0000cd:   1E42        MOVL         *-SP[2], ACC
13          unsigned long int dd = 0;
0000ce:   1E44        MOVL         *-SP[4], ACC
15          cc += ((long)xx)*((long)xx);
0000cf:   761F000C    MOVW         DP, #0xc
0000d1:   2D08        MOV          T, @0x8
0000d2:   3608        MPYU         ACC, T, @0x8
0000d3:   0742        ADDL         ACC, *-SP[2]
0000d4:   1E42        MOVL         *-SP[2], ACC
16          dd += ((long)yy)*((long)yy);
0000d5:   2D09        MOV          T, @0x9
0000d6:   1209        MPY          ACC, T, @0x9
0000d7:   0744        ADDL         ACC, *-SP[4]
0000d8:   1E44        MOVL         *-SP[4], ACC
18      	return 0;
0000d9:   9A00        MOVB         AL, #0x0
19      }
0000da:   FE84        SUBB         SP, #4
0000db:   0006        LRETR