Hi all,

I encounter a strange behaviour with the pic14 target of sdcc. I'm
posting this here first instead of reporting a bug because I'm not very
experienced with sdcc yet and I want to make sure that it's not actually
my own fault.

The problem is that a simple piece of code produces wrong assembler
code. I have a little LCD control function such as 

static void display_data(unsigned char c)
{
    //PORTA = 0xaa;
    if(cmd_or_data)
    {
        PORTA |= 2;
    }
    else
    {
        PORTA &= ~2;
    }
    PORTB = c; PENABLE;
    c <<= 4;
    PORTB = c;  PENABLE;
    cmd_or_data = DATA;
}

which produces the assembler output

;***
;  pBlock Stats: dbName = C
;***
;entry:  _display_data  ;Function start
; 2 exit points
;has an exit
;1 compiler assigned register :
;   r0x27
;; Starting pCode block
_display_data   ;Function start
; 2 exit points
;       .line   131; "main.c"   static void display_data(unsigned char c)
        BANKSEL r0x27
        MOVWF   r0x27
;;     peep 7 - Removed redundant move
;       .line   134; "main.c"   if(cmd_or_data)
        MOVF    _cmd_or_data,W
        BTFSC   STATUS,2
        GOTO    _00150_DS_
;       .line   136; "main.c"   PORTA |= 2;
        BCF     STATUS,5
        BCF     STATUS,6
        BSF     _PORTB,1  ; <---- ????
        GOTO    _00151_DS_
_00150_DS_
;       .line   140; "main.c"   PORTA &= ~2;
        BCF     STATUS,5
        BCF     STATUS,6
        BCF     _PORTB,1   <---- ????
_00151_DS_

(snip)

So I believe the compiler confuses PORTA and PORTB here. However, when
the commented first line of the function body is uncommented, the output
is correct:

;***
;  pBlock Stats: dbName = C
;***
;entry:  _display_data  ;Function start
; 2 exit points
;has an exit
;1 compiler assigned register :
;   r0x27
;; Starting pCode block
_display_data   ;Function start
; 2 exit points
;       .line   131; "main.c"   static void display_data(unsigned char c)
        BANKSEL r0x27
        MOVWF   r0x27
;       .line   133; "main.c"   PORTA = 0xaa;
        MOVLW   0xaa
        BCF     STATUS,5
        BCF     STATUS,6
        MOVWF   _PORTA
;;     peep 7 - Removed redundant move
;       .line   134; "main.c"   if(cmd_or_data)
        BANKSEL _cmd_or_data
        MOVF    _cmd_or_data,W
        BTFSC   STATUS,2
        GOTO    _00150_DS_
;       .line   136; "main.c"   PORTA |= 2;
        BCF     STATUS,5
        BCF     STATUS,6
        BSF     _PORTA,1 <--------- !!
        GOTO    _00151_DS_
_00150_DS_
;       .line   140; "main.c"   PORTA &= ~2;
        BCF     STATUS,5
        BCF     STATUS,6
        BCF     _PORTA,1 <--------- !!

The compilation command is      sdcc -mpic14 --no-pcode-opt -p16f628 main.c

I used the 2.6.0 version of the compiler on Linux, built from the
sources. Please let me know if any other info is missing. 


Best regards,
Dietmar



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to