Author Topic: Pointers memory location  (Read 8943 times)

0 Members and 1 Guest are viewing this topic.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Pointers memory location
« on: May 13, 2010, 07:15:44 pm »
There's something I wondered for a while but I couldn,t find where is it: Would it be possible to know what's the memory address equivalent of each pointers, like Str1, Str2, etc? I was wondering since I was afraid that for example, if I stored way too many things in Str1, that I could overflow on the next pointer below, and if each pointers doesn't have a specific memory location, I can,t seems to wrap my mind about how Axe parser decides which RAM address to allocate a pointer to

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Pointers memory location
« Reply #1 on: May 13, 2010, 08:23:56 pm »
IIRC, data is just tacked on at the end and the address it is put at is the address.
What do you mean by storing to Str1 too many times? If you store something to Str1 like "Text Here"->Str1 and later in your code use "Other TEXT"->Str1, it will just fail to compile.
If you're talking about creating arrays, then if you're not careful, yeah, you can overflow by storing past the end (this is why C is so much fun).
At any rate, If you need to know the addr from inside the program, the pointer is just a number.
For example:
Code: [Select]
"Demo Text"->Str1
"More Text"->Str2
Str2-Str1->X
If X<<0
-X->X
End
Disp X->Dec,i
will tell how far apart the beginning of Str2 is from Str1, regardless of order of the two (Well, it should. I haven't tried)
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Pointers memory location
« Reply #2 on: May 13, 2010, 08:28:10 pm »
What I meant about storing to Str1 too much was for example, if I did 1->{Str1+255}, how am I sure there isn't something else within that 255 bytes range?

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Pointers memory location
« Reply #3 on: May 13, 2010, 08:32:49 pm »
Oh. you don't. (again why C is so much fun)
If you want a large, arbitrary amount of RAM, use L1 to L6.
I don't think Quigibo has added a command to create arbitrary-length empty space in a program yet. (Not sure he ever will).
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Pointers memory location
« Reply #4 on: May 13, 2010, 08:40:31 pm »
I am confused even more now x.x

I guess I'll wait until he awnsers. I am just worried if for example I use both Str1 and Str2 that I end up accidentally overwriting stuff on Str1 while storing values early in Str2 or vice versa

Btw what does arbitrary means?

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Pointers memory location
« Reply #5 on: May 13, 2010, 08:47:41 pm »
Well, these Strings you are using, they are not actualy Strings.  They just hold data, like Pic's, and GDB's.  In fact there is absolutely no different from using the String token and using the Pic tokens.  You can do this, for example:

[1020304050]->Str1
"Textness"->Pic1

And it will compile fine.  When you store text into a String (or wherever it is you store it) all the data of the String is converted to hex and stored just like you would store regular data.  This means that when you compile the program, the pointer (Str1) only has a finite amount of space after it before you start running into other pointers.  The only way to know that you are not overwriting other pointers is to keep track of how many bytes are in your original String.

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Pointers memory location
« Reply #6 on: May 13, 2010, 08:49:07 pm »
anything you specify, nothing in particular, any amount...
sorry if that doesn't help, i'm not a dictionary.
I guess the main thing is that you can't know.
If you're using strings (not necessarily Str1, etc. but storing a string to some pointer), there is one useful piece of knowledge: all strings end with 00 (not characters, byte)
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Pointers memory location
« Reply #7 on: May 13, 2010, 08:55:38 pm »
I don't think Quigibo has added a command to create arbitrary-length empty space in a program yet. (Not sure he ever will).
He has:
det(SIZE)    Adds Size bytes of zeros to program memory.


I'll try to explain:
When everything's compiled, it just is stored as a number.  Ex:
[FFFFFFFFFFFFFFFF]->Pic1
"ABCD->Str1
This is appended onto the end of the file like this:
255 255 255 255 255 255 255 255 65 66 67 68
What does this have to do with the actual content? Nothing.  Since each has a different command, it manipulates each data a certain way.  This is actually how it works. :)
(255 = FF in decimal, as hex numbers are compressed as they are stored.) :)
(65 = ASCII value for 'A', 66 for 'B'...)

Make sense? ;D
« Last Edit: May 13, 2010, 08:56:24 pm by ztrumpet »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Pointers memory location
« Reply #8 on: May 13, 2010, 09:26:00 pm »
I give up, at least until Quigibo awnsers. I get confused even more as people explains. Disregard my topic.

_player1537

  • Guest
Re: Pointers memory location
« Reply #9 on: May 13, 2010, 09:37:05 pm »
I've been wondering something similar to this:
is there a way we can use labels like we can in ASM?  like I know Sub() calls the function.  Is there a way to go "{LBL AA}"  if not, would that be hard to implement?

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Pointers memory location
« Reply #10 on: May 13, 2010, 09:38:35 pm »
I've been wondering something similar to this:
is there a way we can use labels like we can in ASM?  like I know Sub() calls the function.  Is there a way to go "{LBL AA}"  if not, would that be hard to implement?
Yes,
Goto AA
:D
It's actually that simple. :)

_player1537

  • Guest
Re: Pointers memory location
« Reply #11 on: May 13, 2010, 09:42:12 pm »
oh, didn't know about that, cool :)

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Pointers memory location
« Reply #12 on: May 14, 2010, 12:28:38 am »
After re-reading your post, it sounds like you're worried that if you have too much data in one pointer location, that it would somehow be possible to overflow into another pointer location?  It would never happen.  If you had that much data, the program would not compile becasue it would be past the program size limit.

What you might also be asking is how to make sure that when writing over data in Str1 (I assume a string in memory) it doesn't overwrite anything in Str2 (A string in memory right after Str1)

This is simple.  First, if you know what size Str1 is, lets say the string is 20 characters long, then just make sure you don't write past 20 characters.  If you don't know the length off-hand, then just make sure that the pointer is less than the Str2 pointer.  This routine writes a character D to Str1 at position A only if it does not overflow into Str2:

:If Str1+A<Str2
:D->{Str1+A}
:End

Sorry if I'm misunderstanding the question.  I will now explain how Axe decides what pointers to assign to your data.  During the first parsing "pass", it creates the entire program minus the data.  On the second pass, it now knows where the executable ends, so it reads through the code and every time it sees you creating data, it adds it to the end of the program.  It will be in exactly the order you have declared the data in.

So if the compiled program, ends at address 9000, then it might read through until it encounters your first data, lets say its a 10 character string Str1.  It will create Str1's pointer at 9000 and then fill up that memory with the letters in the string until it gets to 9010.  Then your next data might be another 10 character string Str2.  So Str2 now equals 9010 and it fills up data until it gets to 9020.  If that's all the data, then your final program size will be all the compiled code plus the data.
« Last Edit: May 14, 2010, 12:28:54 am by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Pointers memory location
« Reply #13 on: May 14, 2010, 12:34:04 am »
OOOH now I finally get it, so pointers are stored right after each others and their size is defined when you store the data (for example [FFFFFF] being 3 bytes). I get it now. Exactly what I wanted to know. Thanks a lot!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Pointers memory location
« Reply #14 on: May 26, 2010, 09:34:22 pm »
Another question about memory location and pointers:

In the manual, it's mentionned that for static pointers, the data you store there cannot be changed. However, in the event where you would add a buffer at the end of your program with the det(SIZE) command, can the data you store there be overwritten when you need to, or do you absolutely have to use SafeRAM locations for such purpose?