I tried passing a variables to a subroutine. BYTE values are passed correctly but WORD values seem to overflow and only a byte value is printed in the Sub. Some examples:
Main Program value is 98 (BYTE) this shows up as 98 in the Sub which is correct.
Main Program value is 312 (WORD) this shows up as 56 in the Sub which is wrong.
Main Program value is 876 (WORD) this shows up as 108 in the Sub which is wrong.
'NOTE - - The 98 produces 98 here.
' The 312 produces 56 here.
'The 876 produces 108 here.
' i.e. Only BYTE values are passed correctly.
' WORD variables overflow.
End Sub
Last edit: Anobium 2015-09-21
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am using the 0.94 version.
I tried passing a variables to a subroutine. BYTE values are passed correctly but WORD values seem to overflow and only a byte value is printed in the Sub. Some examples:
What am I doing wrong?
Here is my code.
~~~~
;Chip Settings
chip 18F4550,48
config PLLDIV=1, CPUDIV=OSC1_PLL2, OSC=HSPLL_HS, MCLRE=ON, LVP=OFF
;Defines (Constants)
define LCD_IO 2
define LCD_CB PORTC.1
define LCD_DB PORTC.2
;Variables
Dim X_In As word
'
Do_Again:
X_In = 98
locate 0, 0
print "Input = "
print X_In
Put_WordValue_into_Sub
'
X_In = 312
locate 0, 0
print "Input = "
print X_In
Put_WordValue_into_Sub
'
X_In = 876
locate 0, 0
print "Input = "
print X_In
Put_WordValue_into_Sub
'
goto Do_Again
'
Sub Put_WordValue_into_Sub (X_In As word)
locate 1, 0
print "Ouput = "
print X_In
wait 1 s
cls
'NOTE - - The 98 produces 98 here.
' The 312 produces 56 here.
'The 876 produces 108 here.
' i.e. Only BYTE values are passed correctly.
' WORD variables overflow.
End Sub
Last edit: Anobium 2015-09-21
I think I found the problem.
Changing this :
Put_WordValue_into_Sub
to this:
Put_WordValue_into_Sub (X_In)
fixed the problem.
Yes you are correct - you do need to pass parameter(s).
In the next release of the compiler you will get an error showing a missing parameter - like the one you were missing.
:-)