View previous topic :: View next topic |
Author |
Message |
RWo
Joined: 23 Sep 2015 Posts: 22
|
Posted: Sat Oct 10, 2015 8:20 am Post subject: Array kills local variables? |
|
|
I need some help pls,
this code delete (or what ever) the contence of var "txt1"
Is the somting wrong in this declaration of SUB Test?
Code: |
$Regfile="m32def.dat"
$Crystal=14745600
$hwstack = 40
$swstack = 16
$framesize = 32
$baud = 19200
$sim
Declare Sub Test(Pins() as Byte)
Config Com1 = Dummy , Synchrone = 0 , Parity = none , Stopbits = 1 , Databits = 8 _
Clockpol = 1
Config Portc = Input
dim a as byte
dim Pins(5) as byte
a = 1
do
Pins(a) = PINC
Call Test (Pins())
Wait 1
Loop
END
Sub Test(Pins() as Byte)
Local a as byte
Local txt1 as String * 16
Local txt2 as String * 16
a = 1
txt1 = "aaa"
txt2 = "bbb" 'Err
Print txt1; txt2; bin(Pins(a))
End Sub
|
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Oct 10, 2015 8:30 am Post subject: |
|
|
$framesize is too small, increase.
The frame holds local variables, your locals are 35 byte in size (each string including terminator 17 byte and var a), also function arguments need some space too.
You can easily test that with the simulator, select the tab "locals" to watch them, while single stepping trough the interesting part of code. |
|
Back to top |
|
|
RWo
Joined: 23 Sep 2015 Posts: 22
|
Posted: Sat Oct 10, 2015 10:09 am Post subject: |
|
|
Thank You,
yes indeed - a real beginner mistake...
By the way, is...
Local a as Byte
Local b as Byte
same as
Local a as Byte, b as Byte
?
Thank you |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Oct 10, 2015 11:08 am Post subject: |
|
|
RWo wrote: | By the way, is...
Local a as Byte
Local b as Byte
same as
Local a as Byte, b as Byte |
Same nomenclature as with Dim, so the answer is: Yes. |
|
Back to top |
|
|
|