kent_twt4 - 2008-08-21

Calling attention to using overloaded subs that Hugh has added to GCBasic, Thanks!!!

Always wondered how some compiler dialects were using subs with the same name, and passing different lengths of parameters/variables in the same program.  Well can't quite say I understand it fully, but it works, just check the subs in the assembly file.

'Overloaded sub test with GCBasic and Pickit 2 low pin count board.
'An Overloaded sub, is calling the same sub name with different
'lengths of parameters; or the same parameter length, with different
'type of parameters, within the same program.

#chip 16f690,8
#config Osc=INTRC_OSC_NOCLKOUT

dir PortC out
dim test as word
dim test3 as word
test1 = 1
test2 = 2
test3 = 4
test4 = 8

Main:
testOverload (test1,test2)
PortC = test
wait 3 s
testOverload (test2,test3)
PortC = test
wait 2 s
testOverload(test1,test2,test3,test4)
PortC = test
wait 1 s
PortC = 0
wait 1 s
goto main

'Test overloaded sub.  That is same sub name with different
'length of parameters, or same length and different type of parameters
Sub testOverload (test1,test2)
test = test1 + test2
end sub

Sub testOverload (test2,test3 as word)
test = test2 * test3
end sub

Sub testOverload (test1,test2,test3 as word,test4)
test = test1+test2+test3+test4
end sub

'The assembly;

;********************************************************************************

;TESTOVERLOAD (BYTE,BYTE,WORD,BYTE)
TESTOVERLOAD3
    movf    TEST2,W
    addwf    TEST1,W
    movwf    SysTemp1
    movf    TEST3,W
    addwf    SysTemp1,W
    movwf    SysTemp2
    movf    TEST3_H,W
    btfsc    STATUS,C
    addlw    1
    movwf    SysTemp2_H
    movf    TEST4,W
    addwf    SysTemp2,W
    movwf    TEST
    clrw
    btfsc    STATUS,C
    addlw    1
    addwf    SysTemp2_H,W
    movwf    TEST_H
    return

;********************************************************************************

;TESTOVERLOAD (BYTE,BYTE)
TESTOVERLOAD1
    movf    TEST2,W
    addwf    TEST1,W
    movwf    TEST
    clrw
    btfsc    STATUS,C
    addlw    1
    movwf    TEST_H
    return

;********************************************************************************

;TESTOVERLOAD (BYTE,WORD)
TESTOVERLOAD2
    movf    TEST2,W
    movwf    SysCalcTempA
    clrf    SysCalcTempA_H
    movf    TEST3_H,W
    movwf    SysCalcTempB_H
    movf    TEST3,W
    movwf    SysCalcTempB
    call    SysMultSub16
    movf    SysCalcTempX_H,W
    movwf    TEST_H
    movf    SysCalcTempX,W
    movwf    TEST
    return