Menu

8051 __reentrant function bug?

ncb48
2011-04-06
2013-03-12
  • ncb48

    ncb48 - 2011-04-06

    I have this function in my main.c

    /**
    * power function
    */
    void power() __reentrant {
        unsigned int i,j;
        unsigned long result;
        for (i=0; i<100; i++) {
            for (j=0; j<1000; j++) {
            }
            result = 1;
            for (j=0; j<31; j++) {
                result *= 2;
            }
            if (result != 2147483648) {
                put_char('f');
                break;
            }
        }
    }

    Wenn I look at the generated code, i see this:
                                430 ;----------------------------------------
                                431 ;Allocation info for local variables in function 'power'
                                432 ;----------------------------------------
                                433 ;i                         Allocated to stack - offset 1
                                434 ;j                         Allocated to registers r4 r5
                                435 ;result                    Allocated to registers r4 r5 r6 r7
                                436 ;----------------------------------------
                                437 ; main.c:40: void power() __reentrant {

    Only "i" ist on the stack, remaining variables are in registeres. Is this a bug in sdcc ? According to manual, chapter 3.7 Parameters & Local Variables they should all be on the stack.

     
  • Maarten Brock

    Maarten Brock - 2011-04-06

    Not if they can be held in registers.

     

Log in to post a comment.