When I do an HSerPrint of a concatated string, and also do an operation with a variable declared as Long, there is some sort of interaction that trashes the values in one of my other arrays.
example:
#optionExplicit#chip16LF1938,32#defineUSART_BAUD_RATE115200'460800 '460800'921600 '230400'115200#define USART_TX_BLOCKING#define prt HSerPrintdim seg(9)dim iidim timel,timehdim bigtime as longprt "test"for ii=1 to 8:seg(ii)=63:next ii 'presetallvaluesto63prtchr(27):prt"[5;1H"for ii=1 to 8 prt seg(ii):prt "" ' print out values before the concatenationnext iprt chr(27):prt "[3;1H"prt "abcde"+"fghij" ' this caused the problemprt chr(27):prt "[6;1H"for ii=1 to 8 prt seg(ii):prt "" ' print out values after the concatenationnext idoloop' the rest is the original program stripped down to the' minimum that still affects the problemtimel=TMR1Ltimeh=TMR1H-0x80 ' subtract out starting amountbigtime=timeh*256+timel ' ** this instruction causes the problem
Note that if I comment out the last line, the problem doesn't occur, even though it is never executed.
But it doesn't give me a clue where the compiler overlapped the seg array.
To be clear, the problem does not occur if two separate HSerPrints are done, one for each string, it's only the concatination of the two strings within one print that causes the problem.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Check the first code example. This is the easier way to reproduce,
Use the workaround. Shown in second example.
#chip16f877a
#optionexplicitdimseg(9)dimiiforii=1to8:seg(ii)=63:nextii'preset all values to 63for ii=1 to 8 epwrite ii,seg(ii)next iipassedsub("abcde"+"fghij")' this caused the problemfor ii=1 to 8 epwrite ii+16,seg(ii)next iisub passedsub( instring as string )end sub
To work around, concat first then pass as a parameter.
My guess, you know this already.
#chip16f877a
#optionexplicitdimseg(9)dimiiforii=1to8:seg(ii)=63:nextii'preset all values to 63for ii=1 to 8 epwrite ii,seg(ii)next iidim mystring as stringmystring = "abcde"+"fghij"passedsub(mystring)' this will not cause a problemfor ii=1 to 8 epwrite ii+16,seg(ii)next iisub passedsub( instring as string )end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
But, we need to resolve to avoid this issue in the future.
#chip 16f877a
#option explicit
dim seg(9)
dim ii
for ii=1 to 8:seg(ii)=63:next ii 'preset all values to 63
for ii=1 to 8
epwrite ii,seg(ii)
next ii
passedsub ( concat("abcde","fghij") ) ' this resovles the problem
for ii=1 to 8
epwrite ii+16,seg(ii)
next ii
sub passedsub( instring as string )
end sub
function concat ( instring1 as string, instring2 as string ) as string * 40
concat = instring1 + instring2
end Function
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When I do an HSerPrint of a concatated string, and also do an operation with a variable declared as Long, there is some sort of interaction that trashes the values in one of my other arrays.
example:
Note that if I comment out the last line, the problem doesn't occur, even though it is never executed.
The result look like:
°°est
abcdefghij
63 63 63 63 63 63 63 63
103 104 105 106 63 63 63 63
so you can see that the first four values of the seg array were changed to "ghij"
I have seen this before. Try.
I think it is the terminal processes the <esc>. </esc>
My test on a 16f1938
and, you can use... Timer1 and cut that code.
bigtime=Timer1
that's two interesting things, but it has no effect of what is trashing the seg array.
What interaction would change the first four values in and unrelated array.
It seems the compiler is overlapping a declared array with some of it's intermediate values, not a good thing.
Is it? I think not.
Where is it in my response? I dont understand the issue - me thinks.
What version of compiler etc. Look at the first line of the ASM
;Program compiled by Great Cow BASIC (0.98.06 2019-06-12 (Windows 32 bit))
I guess I'm missing something here.
This is the seg array before the print -
63 63 63 63 63 63 63 63
and after doing - HSerPrint "abcde"+"fghij"
here is the seg array after that print-
103 104 105 106 63 63 63 63
Why would an HSerPrint change the values in an unrelated array?
Notice that the values changed were changed to 103,104,105,106 which is ascii for "ghij"
So the compiler put together code that used the first part of my array for scratch.
From the asm file-
But it doesn't give me a clue where the compiler overlapped the seg array.
To be clear, the problem does not occur if two separate HSerPrints are done, one for each string, it's only the concatination of the two strings within one print that causes the problem.
What version of compiler etc. Look at the first line of the ASM
;Program compiled by Great Cow BASIC (0.98.06 2019-06-12 (Windows 32 bit))
Leave it with me. I need to examine in a debugger.
Thanks for version info.
Look like a bug.
Check the first code example. This is the easier way to reproduce,
Use the workaround. Shown in second example.
To work around, concat first then pass as a parameter.
My guess, you know this already.
Another way to resolve.... add a CONCAT function.
But, we need to resolve to avoid this issue in the future.