sdcc bug? pic 16f690

Help
2010-01-08
2013-03-12
  • sifourquier
    sifourquier
    2010-01-08

    Hello I have a bug in a program

     

    if(cal_val_pwm>25)
    erreur=1;
    else
    erreur=0;
    if(cal_val_pwm>25)
    {

    What is strange was that when compiling the assembly code of the 2 « if(cal_val_pwm>25) » is not identical
    in practice it goes from time to time in the 2nd then it should not

     

    ;.line 74; "test.c" if(cal_val_pwm>25)
    MOVLW 0x1a
    SUBWF r0x1006,W
    CLRF r0x1007
    RLF r0x1007,F
    BTFSS STATUS,0
    GOTO _00112_DS_
    ;genSkipc:3225: created from rifx:0x7fff0dd56040
    ; .line 75; "test.c" erreur=1;
    MOVLW 0x01
    BANKSEL _erreur
    MOVWF _erreur
    GOTO _00113_DS_
    _00112_DS_
    ; .line 77; "test.c" erreur=0;
    BANKSEL _erreur
    CLRF _erreur
    _00113_DS_
    ; .line 78; "test.c" if(cal_val_pwm>25)
    MOVLW 0x00  ;<- SUBWF ??
    BANKSEL r0x1007
    IORWF r0x1007,W
    BTFSC STATUS,2
    GOTO _00129_DS_
     

    sdcc -version
    SDCC : avr/pic16/pic14/xa51 2.8.0 #5117 (Jun  2 2008) (UNIX)

    piklab complete file for piklab http://cortexet.free.fr/pic

    If you have any idea thank you

     
  • Raphael Neider
    Raphael Neider
    2010-01-08

    Yes, there is a bug here.

    The first if puts the result of the comparison into r0x0007: SUBWF sets the CARRY bit (STATUS<0>) iff W <= f (0x1a == 26 <= cal_val_pwm or cal_val_pwm > 25. RLF rotates (!) r0x1007 (0x00) through the CARRY bit, always clearing CARRY and setting r0x1007 == 1 iff the comparison was true, 0 otherwise. The following BTFSS STATUS, 0 tests the CARRY bit, which is wrong (always false, i suppose; erreur should never be set …).
    The second if reuses the result from r0x1007 by comparing r0x1007 to 0: r0x1007 was 1 iff cal_val_pwm > 25 and 0 otherwise, so IORWF r0x1007 sets ZERO (CARRY<2>) iff the comparison is false <==> clears ZERO iff the comparison is true, which is honored by the BTFSC.

    The first if is broken, the second one is OK.

    I will try to fix this by the weekend …

    Raphael

     
  • sifourquier
    sifourquier
    2010-01-08

    I did not understand everything (my assembler knowledge is very limited)
    but I think that was the 1st test that works well and not the 2nd

     
  • Raphael Neider
    Raphael Neider
    2010-01-10

    I committed a fix for this bug (first test broken, second one OK) as SDCC 2.6.9, r5626.
    Please download and install a snapshot containing r5626 (probably available by tomorrow at sdcc.sf.net/snap.php) or the svn head and try again. If your error persists, please report back.

    Best regards

    Raphael

     
  • sifourquier
    sifourquier
    2010-01-11

    There was a problem with the Snapshot 5627?It is only 2K (and svn does not compile I redo a test tomorrow) enfaite you do not speak French by chance

     
  • sifourquier
    sifourquier
    2010-01-12

    The 2 if does not always give the same asm code but when the program enters a if he enters another. my program bug from time to time he spent in the if, so it should not I'll watch it just me or sdcc (I know when I have the time).

    thank you sdcc is the only compiler that I find open source and unrestricted

    ;unsigned compare: left < lit(0x19=25), size=1
    ; .line 74; "test.c" if(cal_val_pwm>=25)
    MOVLW 0x19
    SUBWF r0x1006,W
    CLRF r0x1007
    BTFSS STATUS,0
    BSF r0x1007,0
    BTFSS STATUS,0
    GOTO _00112_DS_
    ;genSkipc:3057: created from rifx:0x7fffd00bdbd0
    ; .line 75; "test.c" erreur=1;
    MOVLW 0x01
    BANKSEL _erreur
    MOVWF _erreur
    GOTO _00113_DS_
    _00112_DS_
    ; .line 77; "test.c" erreur=0;
    BANKSEL _erreur
    CLRF _erreur
    _00113_DS_
    ; .line 78; "test.c" if(cal_val_pwm>=25)
    MOVLW 0x00
    BANKSEL r0x1007
    IORWF r0x1007,W
    BTFSS STATUS,2
    GOTO _00129_DS_

     
  • sifourquier
    sifourquier
    2010-01-12

    I think it's a division that a problem was possible?

    ; .line 77; "test.c" cal_val_pwm=cal_val_pwm/3;
    MOVLW 0x03
    MOVWF STK00
    BANKSEL r0x1006
    MOVF r0x1006,W
    PAGESEL __divuchar
    CALL __divuchar
    PAGESEL $
    BANKSEL r0x1006
    MOVWF r0x1006

    Before the division cal_val_pwm is stable but after it is not stable
    I not have material for the step to step I display the value on LEDs (PICKIT2)

     
  • sifourquier
    sifourquier
    2010-01-15

    I just test with the compiler from HI-TECH and my code was running so I think that was quite another bug sdcc