Simple byte array problem

Hi everyone - I am having trouble understanding my problem with the attached SPIN code. I initially set a byte array ( Byte TextArray[12] ) to contain the 5-characters "Hello" using a String statement:
TextString := String("Hello")
and it works just fine. Then I attmpt to change the first array element from an "H" to an "h" using the following:
TextString[0] := "h"
which completely screws somethig up since I get garbage when trying to display the contents of TextString on the terminal. I get the same result if I try using the hexidecimal code for "h" as well:
TextArray[0] := $68
Can anyone tell me what I'm doing wrong here? Attached is the SPIN code file I'm using.
TextString := String("Hello")
and it works just fine. Then I attmpt to change the first array element from an "H" to an "h" using the following:
TextString[0] := "h"
which completely screws somethig up since I get garbage when trying to display the contents of TextString on the terminal. I get the same result if I try using the hexidecimal code for "h" as well:
TextArray[0] := $68
Can anyone tell me what I'm doing wrong here? Attached is the SPIN code file I'm using.
Comments
-Phil
I'm afraid I don't understand why the bytemove command is needed when all I want to do is to change a single byte in the array from "H" to "h". Are you saying I need to do this:
bytemove( @TextString[ 0 ], $68, 1 )
instead of:
TextString[ 0 ] := $68
??
bytemove(@TextString, string("Hello"), 6) 'Copy "Hello" to TextString. TextString[0] := "h" 'Change the first letter.
-Phil
In your code you're writing the address in your program where the Spin compiler stuck "text",0 into the numeric variable TextString. This needs to be a word or long since it's a pointer to a Hub RAM address. If you were to do something like BYTE[textstring + 2] := "s" you could change the characters of the string image. But if you want to manipulate the string without altering your original code, you need to do something like this:
var
byte mystring[8]
pub
bytemove(@mystring, string("mytext"),7)
mystring[2] := "s"
Then, you could alter it the way you initially intended, by doing TextString[ 0 ] := $68
To use the string you'd usually pass the address of the string, @TextString.
PUB packetTemplate[9] := "F" packetTemplate[10] := "F" ' now packetTemplate array equals "what is $FF + $00?", 0 DAT ' I use the numbers to help keep track of which elements to change. '1 2 3 '01234567890123456789012345678901 packetTemplate byte "what is $00 + $00?", 0
Duane