This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem with 8051 compiler multiplication/compare statement

Hi,

I made a small program to make the problem clear:

==================

void problem(void)
{
    unsigned char ii;
    unsigned char jj;
    unsigned char flag;

    for (ii=0;ii<0xff;ii++)
    {
         for (jj=0;jj<0xff;jj++)
         {
             if (ii * jj < 0xff)
             {
                 if (ii * (unsigned int)jj < 0xff)
                     flag = 1; // ok
                 else
                     flag = 2; // not ok
             }
         }
     }
}


===================
I have a double for loop, both loop counters are of type unsigned char. When I do a compare: if (ii * jj < 0xff), the outcome sometimes is wrong (flag = 2). That can be checked with the same expression using an explicit (unsigned int) cast.

The first three combinations which yield an incorrect result are:
ii=0x82, jj=0xfd
ii=0x82, jj=0xfe
ii=0x83, jj=0xfb

I am using the following compiler:
C51 COMPILER V9.51 - SN: K1NGC-DAEVIE
COPYRIGHT Copyright (C) 2012 ARM Ltd and ARM Germany GmbH. All rights reserved.

on a C8051F587 processor.

Questions:
o Do you agree that this is a bug in the compiler?
o Is this a known bug?

0