#327 loopreversal optimisation problem

closed-fixed
Bernhard Held
5
2013-05-25
2002-04-17
Anonymous
No

The attached program should do the following:
take a string - in this case "1234" and convert it to a
number 0x1234

( a cut-down version of fscan )

If I compile the program with no command line options :
sdcc main.c

the number is returned as 0x4321

If I use the --noloopreversal option:
sdcc --noloopreversal main.c

the number is returned correctly as 0x1234

I'm using sdcc 2.3.0 under win2000.

Discussion

  • Bernhard Held
    Bernhard Held
    2002-04-26

    Logged In: YES
    user_id=203539

    Attaching files doesn't work. Please post your (stripped
    down) source as a comment.

     
  • Bernhard Held
    Bernhard Held
    2002-04-26

    Logged In: YES
    user_id=203539

    Attaching files doesn't work. Please post your (stripped
    down) source as a comment.

     
  • Logged In: NO

    source file is as follows:

    #include <8051.h>

    unsigned int test(char *buffer);

    /*
    Test program to show bug - fixed by using --noloopreversal option
    */
    void main (void) {
    xdata int store[65536]; // set up array for external memory access

    unsigned int n;

    n = test("1234");
    store[0] = n & 0xf; // send lsb to external memory

    }

    unsigned int test(char *buffer)
    {
    char temp;
    unsigned int f,value;

    value = 0;
    for (f=0;f<4;f++)
    {
    temp = buffer[f];

    value = value << 4; // shift up ready for next char

    temp = temp - 0x30;

    if (temp > 9 )
    temp = temp - 7; // deal with A-F

    if (temp > 15)
    temp = temp - 32; // deal with a-f

    value = value + (unsigned int )temp;
    }
    return value;

    }

     
  • Bernhard Held
    Bernhard Held
    2002-04-26

    • labels: --> mcs51(8051) target
    • milestone: --> fixed
    • assigned_to: nobody --> bernhardheld
    • status: open --> closed-fixed
     
  • Bernhard Held
    Bernhard Held
    2002-04-26

    Logged In: YES
    user_id=203539

    Not reproduceable with 2.3.2.