Menu

if (myvar <> 7) & (myvar <> 8) fails compile

bell
2007-04-03
2013-05-30
  • bell

    bell - 2007-04-03

    This code:
    myvar = 10
    if (myvar <> 7) & (myvar <> 8) then
        myvar = 0
    end if

    Compiles to:
        movlw    10
        movwf    MYVAR
        movf    MYVAR,W
        movwf    SysCalcTempA
        movlw    7
        movwf    SysCalcTempB
        call    SysCompNotEqual
        movf    SysCalcTempX,W
        movwf    SysTemp1
        movf    MYVAR,W
        movwf    SysCalcTempA
        movf    ,W
        movwf    SysCalcTempB
        call    SysCompLessThan
        movf    SysCalcTempX,W
        movwf    SysTemp2
        movf    SysTemp2,W
        movwf    SysCalcTempA
        movlw    8
        movwf    SysCalcTempB
        call    SysCompMoreThan
        movf    SysCalcTempX,W
        movwf    SysTemp3
        movf    SysTemp1,W
        andwf    SysTemp3,W
        movwf    SysIFTemp
        btfss    STATUS, Z
        clrf    MYVAR
    BASPROGRAMEND
        sleep
        goto    $

    Which is wrong and fails on assembling.

    On the other hand this code compiles and assembles without error:

    myvar = 10
    if (myvar ! 7) | (myvar ! 8) then
        myvar = 0
    end if

    But I'm not sure if <> is the same thing as !

     
    • Hugh Considine

      Hugh Considine - 2007-04-03

      Fixed, http://gcbasic.sourceforge.net/newfiles/update.zip

      <> is not the same as !. <> means not equal, ! is the operator for a logical or bitwise NOT. The second example of code you posted compiles without any errors, but the assembly that is generated does not do anything useful.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.