Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

SDCC Generates M51 Assembler Phase errors

Help
2009-04-09
2013-03-12
  • Hi All,

    Any idea why SDCC would generate an assembler source file containing phase errors?

    The problem stems from this routine:

    int gettemp( unsigned long *temp )
    {
        unsigned time;
        unsigned long l;

        AD0INT = 0;                                // clear last conversion
        ADC0MD = 0x82;                            // initiate single conversion
        MScount = 1000;                            // set time-out timer (100 ms)

        while ( MScount > 0 && AD0BUSY ) ;        // wait for conversion
        time = 1000 - MScount;
        outs( "Conversion took: " );
        outdec( time );
        outs( "ms\r\nADC Status: " );
        outhexb( ADC0STA );
        outs( "\r\n" );

        l = ( ( (unsigned long) ADC0H ) << 16 ) + ( ( (unsigned long) ADC0M ) << 8 ) + ( (unsigned long) ADC0L );
        *temp = l;
        ADC0MD = 0x80;
        return( ADC0STA != 0x20 || time < 80 );
    }

    which is translated into:

    ;    C:\SDH Enterprises\FLI\LED Board\Firmware\blinky.c:40: int gettemp( unsigned long *temp )
    ;    -----------------------------------------
    ;     function gettemp
    ;    -----------------------------------------
    _gettemp:
        mov    r2,b
        mov    r3,dph
        mov    a,dpl
        mov    dptr,#_gettemp_temp_1_1
        movx    @dptr,a
        inc    dptr
        mov    a,r3
        movx    @dptr,a
        inc    dptr
        mov    a,r2
        movx    @dptr,a
        C$blinky.c$46$1$1 ==.
    ;    C:\SDH Enterprises\FLI\LED Board\Firmware\blinky.c:46: AD0INT = 0;                                // clear last conversion
        clr    _AD0INT
        C$blinky.c$47$1$1 ==.
    ;    C:\SDH Enterprises\FLI\LED Board\Firmware\blinky.c:47: ADC0MD = 0x82;                            // initiate single conversion
        mov    _ADC0MD,#0x82
        C$blinky.c$48$1$1 ==.
    ;    C:\SDH Enterprises\FLI\LED Board\Firmware\blinky.c:48: MScount = 1000;                            // set time-out timer (100 ms)
        mov    dptr,#_MScount
        mov    a,#0xE8
        movx    @dptr,a
        inc    dptr
        mov    a,#0x03
        movx    @dptr,a
        C$blinky.c$50$1$1 ==.
    ;    C:\SDH Enterprises\FLI\LED Board\Firmware\blinky.c:50: while ( MScount > 0 && AD0BUSY ) ;        // wait for conversion
    00102$:
        mov    dptr,#_MScount
        movx    a,@dptr
        mov    r2,a
        inc    dptr
        movx    a,@dptr
        mov    r3,a
        orl    a,r2
        jz    00104$
        jb    _AD0BUSY,00102$
    00104$:
        C$blinky.c$51$1$1 ==.
    ;    C:\SDH Enterprises\FLI\LED Board\Firmware\blinky.c:51: time = 1000 - MScount;
        mov    dptr,#_MScount
        movx    a,@dptr
        mov    r2,a
        inc    dptr
        movx    a,@dptr
        mov    r3,a
        mov    a,#0xE8
        clr    c
        subb    a,r2
        mov    r2,a
        mov    a,#0x03
        subb    a,r3
        mov    r3,a
        C$blinky.c$52$1$1 ==.
    ;    C:\SDH Enterprises\FLI\LED Board\Firmware\blinky.c:52: outs( "Conversion took: " );
        mov    dptr,#__str_0
        mov    b,#0x80
        push    ar2
        push    ar3
        lcall    _outs
        pop    ar3
        pop    ar2
        C$blinky.c$53$1$1 ==.
    ;    C:\SDH Enterprises\FLI\LED Board\Firmware\blinky.c:53: outdec( time );
        mov    ar4,r2
        mov    ar5,r3
        mov    r6,#0x00
        mov    r7,#0x00
        mov    dpl,r4
        mov    dph,r5
        mov    b,r6
        mov    a,r7
        push    ar2
        push    ar3
        lcall    _outdec
        C$blinky.c$54$1$1 ==.
    ;    C:\SDH Enterprises\FLI\LED Board\Firmware\blinky.c:54: outs( "ms\r\nADC Status: " );
        mov    dptr,#__str_1
        mov    b,#0x80
        lcall    _outs
        C$blinky.c$55$1$1 ==.
    ;    C:\SDH Enterprises\FLI\LED Board\Firmware\blinky.c:55: outhexb( ADC0STA );
        mov    dpl,_ADC0STA
        lcall    _outhexb
        C$blinky.c$56$1$1 ==.
    ;    C:\SDH Enterprises\FLI\LED Board\Firmware\blinky.c:56: outs( "\r\n" );
        mov    dptr,#__str_2
        mov    b,#0x80
        lcall    _outs
        pop    ar3
        pop    ar2
        C$blinky.c$58$1$1 ==.
    ;    C:\SDH Enterprises\FLI\LED Board\Firmware\blinky.c:58: l = ( ( (unsigned long) ADC0H ) << 16 ) + ( ( (unsigned long) ADC0M ) << 8 ) + ( (unsigned long) ADC0L );
        mov    r4,_ADC0H
        mov    r5,#0x00
        mov    (_gettemp_sloc0_1_0 >> 24),r5
        mov    (_gettemp_sloc0_1_0 >> 16),r4
        mov    (_gettemp_sloc0_1_0 >> 8),#0x00
        mov    _gettemp_sloc0_1_0,#0x00
        mov    r4,_ADC0M
        mov    r5,#0x00
        mov    r6,#0x00
        mov    ar7,r6
        mov    ar6,r5
        mov    ar5,r4
        clr    a
        add    a,_gettemp_sloc0_1_0
        mov    _gettemp_sloc0_1_0,a
        mov    a,r5
        addc    a,(_gettemp_sloc0_1_0 >> 8)
        mov    (_gettemp_sloc0_1_0 >> 8),a
        mov    a,r6
        addc    a,(_gettemp_sloc0_1_0 >> 16)
        mov    (_gettemp_sloc0_1_0 >> 16),a
        mov    a,r7
        addc    a,(_gettemp_sloc0_1_0 >> 24)
        mov    (_gettemp_sloc0_1_0 >> 24),a
        mov    r4,_ADC0L
        mov    r5,#0x00
        mov    r6,#0x00
        mov    r7,#0x00
        mov    r0,#_gettemp_l_1_1
        mov    a,r4
        add    a,_gettemp_sloc0_1_0
        mov    @r0,a
        mov    a,r5
        addc    a,(_gettemp_sloc0_1_0 >> 8)
        inc    r0
        mov    @r0,a
        mov    a,r6
        addc    a,(_gettemp_sloc0_1_0 >> 16)
        inc    r0
        mov    @r0,a
        mov    a,r7
        addc    a,(_gettemp_sloc0_1_0 >> 24)
        inc    r0
        mov    @r0,a
        C$blinky.c$59$1$1 ==.
    ;    C:\SDH Enterprises\FLI\LED Board\Firmware\blinky.c:59: *temp = l;
        mov    dptr,#_gettemp_temp_1_1
        movx    a,@dptr
        mov    r4,a
        inc    dptr
        movx    a,@dptr
        mov    r5,a
        inc    dptr
        movx    a,@dptr
        mov    r6,a
        mov    dpl,r4
        mov    dph,r5
        mov    b,r6
        mov    r0,#_gettemp_l_1_1
        mov    a,@r0
        lcall    __gptrput
        inc    dptr
        inc    r0
        mov    a,@r0
        lcall    __gptrput
        inc    dptr
        inc    r0
        mov    a,@r0
        lcall    __gptrput

    All of the statements containing "(_gettemp_sloc0_1_0 >> 24)" in any form or use fail with phase errors during assembly.

    Any thoughts are much appreciated.

    Thanks,

    Scott

     
    • Maarten Brock
      Maarten Brock
      2009-04-09

      What is M51 and what are the exact errors you see?

       
    • Hi Marrten,

      M51 is the CPU (actually it's SiLabs C8051F350).  The errors are from ASXXXX, and are phase errors during the assembly.

      Scott

       
      • I should add that changing the C statement to

        l = ( ADC0H * 65536U + ADC0M * 256 + ADC0L;

        eliminates the problem.

        Scott