Integer bug

2013-10-13
2014-05-02
  • Thomas Henry
    Thomas Henry
    2013-10-13

    Well, let's try this again. A while back I had some problems with INTEGER arithmetic since the newest version. I returned to this tonight and located one problem. Here's the Basic code:

          rh = 256*[integer]values(1)+values(2) ;this is 10*rh
          copy = values(3) & 0x7F       ;save copy of byte 3, less sign 
          cels = 256*[integer]copy+values(4)  ;this is 10*Celsius
    

    And here's the ensuing assembler:

    ;rh = 256*[integer]values(1)+values(2) ;this is 10*rh
        clrf    SysINTEGERTempA
        movlw   1
        movwf   SysINTEGERTempA_H
        banksel SYSVALUES_1
        movf    SYSVALUES_1,W
        movwf   SysINTEGERTempB
        clrf    SysINTEGERTempB_H
        banksel STATUS
        call    SysMultSubINT
        banksel SYSVALUES_2
        movf    SYSVALUES_2,W
        addwf   SysINTEGERTempX,W
        banksel RH                            ;***** BANKSEL
        movwf   RH
        movlw   0
        btfsc   STATUS,C
        addlw   1
        addwf   SysINTEGERTempX_H,W
        movwf   RH_H
    ;copy = values(3) & 0x7F       ;save copy of byte 3, less sign
        movlw   127
        banksel SYSVALUES_3
        andwf   SYSVALUES_3,W
        banksel COPY
        movwf   COPY
    ;cels = 256*[integer]copy+values(4)  ;this is 10*Celsius
        clrf    SysINTEGERTempA
        movlw   1
        movwf   SysINTEGERTempA_H
        movf    COPY,W
        movwf   SysINTEGERTempB
        clrf    SysINTEGERTempB_H
        call    SysMultSubINT
        banksel SYSVALUES_4
        movf    SYSVALUES_4,W
        addwf   SysINTEGERTempX,W
        movwf   CELS                        ;***** NO BANKSEL
        movlw   0
        banksel STATUS
        btfsc   STATUS,C
        addlw   1
        addwf   SysINTEGERTempX_H,W
        movwf   CELS_H
    

    Note the missing BANKSEL. Even though the Basic lines are virtually the same, for whatever reason the BANKSEL fails to appear in the second line. If I manually add it, this portion of the code works as expected.

     
  • Thomas Henry
    Thomas Henry
    2013-10-15

    Okay, I went ahead and used WORD variables instead of INTEGER variables. I kept everything the same throughout.

    It works perfectly.

    So, the bug is definitely in the INTEGER arithmetic routines.

    Thomas Henry

     
  • Anobium
    Anobium
    2014-05-02

    Bug confirmed and fixed. Releases after April 28th 2014 have a fix for this issue.