Menu

error in: word = byte -word2 'when word2>byte

Santiago
2009-08-10
2013-05-30
  • Santiago

    Santiago - 2009-08-10

    Compiling this code with last update :

    dim my_var1 as byte
    dim my_var2 as word
    dim my_var3 as word

    my_var1 = 100
    my_var2 = 200

    my_var3 = my_var1 - my_var2

    now my_var3 should be  -100, for a word variable it should be 35536-100= 35436.
    That is:  my_var3_H=255, my_va3=156

    But i have:my_var3_H=1, my_va3r=156 : my_var3 = 412

    I think the hight byte calculation is not done correctly:

        movf    MY_VAR2,W
        subwf    MY_VAR1,W
        movwf    MY_VAR3
        movf    MY_VAR2_H,W
        btfss    STATUS,C
        addlw    1
        movwf    MY_VAR3_H

    If i force to do word calcs:

    my_var3 = [word]my_var1 - my_var2

    I have this error:
    Error [113] Symbol not previously defined (MY_VAR2_H).

    I used this solution:

    in gcbasic.bas, FUNCTION CompileCalcAdd(), line 2404->

                'Get correct byte of V1

                IF IsConst(V1)  THEN

                    CurrLine = StringListInsert(CurrLine, " movlw " + GetByte(V1, 1))

                    V1H = GetCalcVar("BYTE")

                    CurrLine = StringListInsert(CurrLine, " movwf " + V1H)

                    FreeCalcVar V1
                ElseIf V1Type = "BYTE" THEN '......................................................THIS OPTION ADDED
                    V1H = GetCalcVar("BYTE")
                    CurrLine = StringListInsert(CurrLine, " clrf " + V1H)

                Else

                    V1H = GetByte(V1, 1)

                END IF

    If V2 is byte and V1 is word, there is no problem.

     
    • Santiago

      Santiago - 2009-08-10

      Sorry.. copy/paste error, when forcing to word, the error is with MY_VAR1_H not with  MY_VAR2_H:

      If i force to do word calcs:

      my_var3 = [word]my_var1 - my_var2

      I have this error:
      Error [113] Symbol not previously defined (MY_VAR1_H).

       
    • Hugh Considine

      Hugh Considine - 2009-08-12

      Thanks for letting me know about that bug, I've uploaded another update which fixes it.

       
    • Santiago

      Santiago - 2009-08-13

      Ok.. working now... thanks.

       

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.