Shop OBEX P1 Docs P2 Docs Learn Events
retrieve eeprom address — Parallax Forums

retrieve eeprom address

Marz KrishnaMarz Krishna Posts: 26
edited 2009-09-26 21:42 in BASIC Stamp
is there a way to retrieve the adress of an eeprom variable

eg.

mydata data @10, "My good data"
retrieveaddr var word

retrieveaddr = @mydata

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-09-26 12:49
    Do you mean to read the contents of an address of a Stamp eeprom?

    If so,
    retrieveaddr var byte
     
     
    READ 100, retrieveaddr   ' <<<< !
    
    

    fetches the contents of address 100, placing it in·your VAR retrieveaddr.

    That's covered in·PBASIC Help.
  • Marz KrishnaMarz Krishna Posts: 26
    edited 2009-09-26 17:39
    thanx, but i don't want the content of a known address, i want to retrieve the address of a defined DATA location so it would be easy to create a lookup table based on dynamic data stored in eeprom.

    eg.
    if i have a Data var X at location 100, and i want to move it to location 107 and still be able to use the "x" symbol to access the data..
  • allanlane5allanlane5 Posts: 3,815
    edited 2009-09-26 19:14
    MyData DATA @10 "My Goodness"
    X var word

    X = MyData ' X now equals 10

    The BS2 is very simple. It only HAS 2000 bytes of eeprom to store stuff in. When you say "MyData DATA @10 "whatever" ", 'MyData' IS a 'pointer' to the EEPROM location holding the 'w'. Meaning MyData IS the value 10, which IS the location in eeprom of your data. Note "MyData" is a compile-time label -- meaning it doesn't take up space in memory.

    So:
    MsgOne DATA "My Goodness",0 ' Putting a zero between strings lets the 'STR' modifier stop at the right place
    MsgTwo DATA "Hello again",0

    X = MsgOne
    SEROUT 16, 16864, (STR X) ' Sends "My Goodness"
    X = MsgTwo
    SEROUT 16, 16864, (STR X) ' Sends "Hello again"
  • dev/nulldev/null Posts: 381
    edited 2009-09-26 19:20
    Why do you want to do this? In my 20 years as a programmer I never came across a problem that required me to have a variable alias point at different memory locations.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • Marz KrishnaMarz Krishna Posts: 26
    edited 2009-09-26 19:57
    i would like to have a dynamic set of character string that i can reference from a symbol, but since it's a compile time label the label get's abstracted into a CONSTANT. so if i were to call the symbol it would give the adress it had compile time instead of giving me the opportunity to change the address the symbol points to. if i knew the adress of the symbol data in the eep instructions segment stored at the end of the eep i could change(WRITE) the updated pointer to the new location in memory, thus updating the symbol pointer. Ultimately i want to have dynamic eep data that i can keep neat while referencing symbols.
  • dev/nulldev/null Posts: 381
    edited 2009-09-26 20:11
    As Allan says symbols are compile-time. (this thread is similar to another recent post about wanting to change variable names runtime). It aint doable. In other languages (with big processors and lots of data space) this is accomplished by supporting variable-length string data types. In PBASIC you cant do this.

    I recently did a project were I had lots of variable-string data to store. To keep it organized I used a large external EEPROM, and assigned my strings to large intervals in the memory. Wasting a lot of space but keeping things organized, I was able to reference things without messing up my code with lots of random pointers. The pointers had values in 100 byte intervals.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • Marz KrishnaMarz Krishna Posts: 26
    edited 2009-09-26 21:05
    if parallax were to update stamp editor to output a text file with eeprom symbol addresses it would possible.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-09-26 21:42
    You have to realize that the Stamp stores both code and addresses in a very compact format that crosses byte boundaries, and the very length of a symbol address is compressed as it is embedded in the code. For example, a symbol address might start at $E5.3 that being the third bit in the byte located at $E5. The address then goes backwards in memory and occupies the minimum space, so that for example the address $007 takes 3 fewer bits than the address $035, and all power-of-two addresses such as $001, or $200 take a minimum of space due to special coding. So it is more complicated than you think to fiddle with the code as it sits in the EEPROM image.

    What you describe can probably be done with an auxiliary table in EEPROM that your program has to manage.

    Msg1pointer DATA 10
    Msg2pointer DATA 15
    MsgZpointer DATA 20

    Msg1 @10 DATA "Dogs", 0 ' going to change this to "Beagles"
    Msg2 @15 DATA "Cats", 0
    endofMessages DATA, 20

    If the program needed to change the entry "Dogs" to "Beagles", it would move everything else up by three bytes, overwrite the old entry with the new one, then update all the pointers. This is a pain, especially since it is all in EEPROM. The technique using an external eeprom or a Stamp like the BS2pe, with fixed addresses and enough bytes at each address to store even the longest entry, that would be much easier to manage.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.