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
#defineUSART_TX_BLOCKING
#defineprtHSerPrintdimseg(9)dimiidimtimel,timehdimbigtimeaslongprt"test"forii=1to8:seg(ii)=63:nextii'preset all values to 63prtchr(27):prt"[5;1H"forii=1to8prtseg(ii):prt""' print out values before the concatenationnextiprtchr(27):prt"[3;1H"prt"abcde"+"fghij"' this caused the problemprtchr(27):prt"[6;1H"forii=1to8prtseg(ii):prt""' print out values after the concatenationnextidoloop' 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 63forii=1to8epwriteii,seg(ii)nextiipassedsub("abcde"+"fghij")' this caused the problemforii=1to8epwriteii+16,seg(ii)nextiisubpassedsub(instringasstring)endsub
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 63forii=1to8epwriteii,seg(ii)nextiidimmystringasstringmystring="abcde"+"fghij"passedsub(mystring)' this will not cause a problemforii=1to8epwriteii+16,seg(ii)nextiisubpassedsub(instringasstring)endsub
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.
#chip16f877a
#optionexplicitdimseg(9)dimiiforii=1to8:seg(ii)=63:nextii'preset all values to 63forii=1to8epwriteii,seg(ii)nextiipassedsub(concat("abcde","fghij"))' this resovles the problemforii=1to8epwriteii+16,seg(ii)nextiisubpassedsub(instringasstring)endsubfunctionconcat(instring1asstring, instring2asstring)asstring*40concat=instring1+instring2endFunction
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.