Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: hardyboy16jm on November 03, 2012, 12:14:02 pm

Title: How to change a string's content
Post by: hardyboy16jm on November 03, 2012, 12:14:02 pm
Can somebody tell how to change a string's contents?
Like if I were to say "STRING1" -> Str1
How would I change that because if I just have another line of code that says "1GNIRTS" -> Str1, I get an error that says Duplicate Symbol.
Thank you.
Title: How to change a string's content
Post by: Hayleia on November 03, 2012, 12:20:02 pm
It says Duplicate Symbol because you are using twice the pointer Str1.
Note that Str1 is a pointer, not a string, and Axe is not Basic ;)
What you can do is that:
  "STRING1"→GDB1
  "1GNIRTS"→GDB2

Then, when you need the first string, do that:
  Fill(L1,8,0)
  Copy(GDB1,L1,7)

Now, at the pointer L1, you have a null-terminated string with "STRING1"[00] in it :)
And to get the second string in L1, do that:
  Fill(L1,8,0)
  Copy(GDB2,L1,7)
Title: Re: How to change a string's content
Post by: Deep Toaster on November 03, 2012, 01:14:28 pm
Split this into a new topic from the "Online Axe command index" thread.
Title: Re: How to change a string's content
Post by: shmibs on November 03, 2012, 02:42:34 pm
the difference here is that, in basic, STR1 is the name of an external object that is created in ram when the program is running, and can be modified however you choose. in axe, however, STR1 is a pre-processor directive. there is no actual object named STR1 that is created, and it is not used at all by your running program. STR1 is a label used by the compiler to point to a specific spot in your compiled program itself, so you can't tell it to point to two different places at once, which is what saying "store X" -> STR1 and then "store Y" -> STR1 is doing. the first time the compiler sees that, it appends the data "store X" to your program and then labels that point as STR1 for everything else to use. the second line would, then, be trying to append data at a different spot in the program and tell the compiler that that place is also called "STR1", which is causing an issue.

now, all that being said, it's easy enough to modify data stored at an STR#, GDB#, or PIC# label later on, provided that you are compiling a program, that will run in standard RAM space, rather than an application. you have to use the label as a part of a pointer, though, and store all the number values manually. it's much easier to work with free ram areas outside of your own program, like hayleia showed above.
Title: Re: How to change a string's content
Post by: Hayleia on November 04, 2012, 02:11:47 pm
now, all that being said, it's easy enough to modify data stored at an STR#, GDB#, or PIC# label later on, provided that you are compiling a program, that will run in standard RAM space, rather than an application. you have to use the label as a part of a pointer, though, and store all the number values manually. it's much easier to work with free ram areas outside of your own program, like hayleia showed above.
Yeah, I could have used Str1 (like the original program) but I used L1 to avoid triggering writeback for something that doesn't need it ;)
Title: Re: How to change a string's content
Post by: aeTIos on November 08, 2012, 09:17:36 am
However, you /can/ allocate a part of the RAM as a string but that's kinda double work. (unless you have the data to be stored in the string generated by a routine)