Menu

Expression evalution with function calls bug

2008-01-02
2013-05-30
  • Nobody/Anonymous

    Hi, there is a bug in the expression evaluation when multiple calls to the same function are made: the return value of the first call(s) are overwritten before being used.

    Example program:
    Start:
    b1=fun1(1)+fun1(2)
    goto Start

    function fun1(a1)
    fun1=a1+1
    end function

    Generated assembly:
    START
    0004 3001      00038         movlw   1
    0005 00A0      00039         movwf   A1
    0006 2010      00040         call    FN_FUN1
    0007 3002      00041         movlw   2
    0008 00A0      00042         movwf   A1
    0009 2010      00043         call    FN_FUN1
    000A 0823      00044         movf    FUN1,W
    000B 0723      00045         addwf   FUN1,W
    000C 00A1      00046         movwf   B1
    000D 2804      00047         goto    START

    FN_FUN1
    0010 0A20      00057         incf    A1,W
    0011 00A3      00060         movwf   FUN1
    0012 0008      00061         return

     
    • Nobody/Anonymous

      I ran into this when doing the SSP slave library.  I can't speak to a fix, but the workaround per Hugh is using a script inside your function.  So I believe your FUN1 would equal my RxBuffersize.

      #script  ;GCBasic treats AnyArray(1) as variable
      RxBufferSize = BufferLen
      if BufferLen = 1 then RxBufferSize = 2
      #endscript

       
    • Hugh Considine

      Hugh Considine - 2008-01-07

      That is a bug with functions, which I've fixed in the latest update. I should have checked for it when I dealt with the similar bug in arrays.

      The update is at http://gcbasic.sourceforge.net/newfiles/update.zip or http://gcbasic.sourceforge.net/newfiles/update-nochipdata.zip depending on what chip data files you already have installed. Download the first one if your chip data files are older than 27/9/2007, otherwise download the second one.

       

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.