Author Topic: How to change a string's content  (Read 3070 times)

0 Members and 1 Guest are viewing this topic.

Offline hardyboy16jm

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 7
  • Rating: +0/-0
    • View Profile
How to change a string's content
« 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.

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
How to change a string's content
« Reply #1 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)
« Last Edit: November 03, 2012, 12:21:22 pm by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: How to change a string's content
« Reply #2 on: November 03, 2012, 01:14:28 pm »
Split this into a new topic from the "Online Axe command index" thread.




Offline shmibs

  • しらす丼
  • Administrator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2132
  • Rating: +281/-3
  • try to be ok, ok?
    • View Profile
    • shmibbles.me
Re: How to change a string's content
« Reply #3 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.

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: How to change a string's content
« Reply #4 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 ;)
« Last Edit: November 04, 2012, 02:12:09 pm by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: How to change a string's content
« Reply #5 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)
« Last Edit: November 08, 2012, 09:18:01 am by aeTIos »
I'm not a nerd but I pretend: