Author Topic: [Axe] string help?  (Read 3022 times)

0 Members and 1 Guest are viewing this topic.

Offline zeldaking

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 197
  • Rating: +15/-0
    • View Profile
[Axe] string help?
« on: March 25, 2013, 06:21:51 pm »
Hey everyone, man I haven't posted here in forever.. Anyways I'll commemorate with being a noob and asking some questions that I have been trying to figure out. This is in Axe just to point out. Okay I am trying to display some strings that I have stored (it will make more sense when you see my code I promise), and I want to do something similar to substr( in Ti-basic but haven't figured it out. Here is my structure of storing strings.
Code: [Select]
..Program
:"This is a string   "->Str1P
:"Yet another one "
:"Oh hi, missed me"
So I was wondering, because axe stores the first string at some location and the next two strings follow it in memory, if I could display different string by its self. When I tried it would display all of my strings I had. Example..
Code: [Select]
..Program
:Strings here:
:Clrhome
:0->N   ;N is what string I want to display, 0 being the first.
:Disp N*16+Str1P   ;*16 is length of my string
::Repeat getkey
:end
So yeah. Hopefully somebody understand what I was saying and can help me, thanks.
« Last Edit: March 25, 2013, 06:22:59 pm by zeldaking »

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: [Axe] string help?
« Reply #1 on: March 25, 2013, 06:33:39 pm »
I don't really do axe, but it looks to me like that code will just Display the contents of Str1P since N*16=0.

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: [Axe] string help?
« Reply #2 on: March 25, 2013, 07:05:25 pm »
It sounds to me that you're looking to access an arbitrary nth string in a bunch of consecutive strings, possibly all of the same, known length? If they have the same known length, you basically have the right approach; but don't forget to count the null terminator in the length of each string! If they may not all have the same length, there's a command just for this purpose: stdDev(START STRING,N).

Either way, you need to make a slight modification to your string data for null termination. It's a little annoying, but to fix this you have to manually add a zero byte to the end of each string that's just sitting alone, which is every string except the first.
Spoiler For why:
String data that is "operated" on, like stored to a named pointer or used directly after a Disp comamnd, is automatically given a null terminator, because it is assumed that if you want to operate on string data, you want it to actually be a properly formed and terminated string. However, if the data isn't immediately operated on, no null terminator is added to allow for a method of including strings without the automatic null termination if necessary. So your first string will be given an automatic null terminator, but the rest will not.

Anyways, in the end, your example program would look something like the code below. I removed the extra spaces at the end of the first string so all the strings had the same length in case the first method was what you were going for. Note that the length of each string's data is actually 17 bytes when you include each string's null terminator!

Code: [Select]
:.PROGRAM
:
:"This is a string"→Str1P
:"Yet another one "[00]
:"Oh hi, missed me"[00]
:
:0→N
:.FIXED LENGTH METHOD
:Disp N*17+Str1P
:.ARBITRARY LENGTH METHOD
:.Disp stdDev(Str1P,N)
:
:Repeat getKey
:End
« Last Edit: March 25, 2013, 07:06:43 pm by Runer112 »

Offline zeldaking

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 197
  • Rating: +15/-0
    • View Profile
Re: [Axe] string help?
« Reply #3 on: March 27, 2013, 06:11:39 pm »
So I have to add those extra null byte at the end?

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: [Axe] string help?
« Reply #4 on: March 29, 2013, 05:13:55 am »
Yes because strings are null terminated in AXE

This will add the null automatically.
Code: [Select]
:"This is a string"→Str1P
This code puts this string in ram: "This is a string"[00]"Yet another one Oh hi, missed me"[unknown bytes, so you don't know if it terminates here]
Code: [Select]
:"This is a string"→Str1P
:"Yet another one "
:"Oh hi, missed me"
« Last Edit: March 29, 2013, 05:16:57 am by Keoni29 »
If you like my work: why not give me an internet?