Shop OBEX P1 Docs P2 Docs Learn Events
How/where do constant strings get stored? — Parallax Forums

How/where do constant strings get stored?

Andy FoxAndy Fox Posts: 46
edited 2007-11-30 20:56 in BASIC Stamp
Have a question here for all the BASIC Stamp experts. I noticed a bit ago that while viewing the memory map layout of my PBASIC 2.0 programs in the BASIC Stamp Editor, I don't see any ASCII strings stored in the EEPROM memory space along with the rest of my program's P-Code, so I'm wondering, where do constant strings like the 'HELLO WORLD' in DEBUG "HELLO WORLD" go? Do the strings get converted to some encrypted format or are they missing from the memory map display?

Comments

  • ZootZoot Posts: 2,227
    edited 2007-11-27 20:32
    They are in there, but the commands (instructions/code) will be in a "tokenized" (i.e., translated) form AND any string characters will appear as their ASCII HEX codes (e.g., $30 is "0"). Since the whole program is tokenized, a DEBUG will appear as some hex tokens (interpreter commands), then at some point the parameters (with your string of ASCII bytes), etc.

    If you want to "see" a string, just for poops n' giggles, it may be easier to put a string into a DATA statement -- data gets tokenized at the top of the memory map, program code at the bottom:

    
    pntr VAR Word
    ioByte VAR Byte
    
    Foo DATA "Hello world!", 0  'Z terminated string
    
    Reset:
    Main:
    
    DEBUG CLS ' clear the screen
    
    Show_ASCII:
    pntr = Foo ' point to date
    DO ' read bytes until 0 reached
       READ pntr, ioByte ' read the char
       IF ioByte = 0 THEN Show_Hex ' yer done
       DEBUG ioByte '
       pntr = pntr + 1 ' next char
    LOOP
    DEBUG CR ' return
    
    Show_Hex:
    pntr = Foo ' point to date
    DO ' read bytes until 0 reached
       READ pntr, ioByte ' read the char
       IF ioByte = 0 THEN Done
       DEBUG IHEX2 ioByte, " "
       pntr = pntr + 1 ' next char
    LOOP
    
    Done:
    GOTO Done
    
    
    



    If you look at the memory map, the hex bytes at the top of the map (starting at address $000) should be the same as the output of "show_hex".

    One of the appendices of the Stamp Manual has the ASCII character chart, which shows ASCII characters and their hex/decimal equivalents.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • Andy FoxAndy Fox Posts: 46
    edited 2007-11-27 21:37
    Zoot said...

    They are in there, but the commands (instructions/code) will be in a "tokenized" (i.e., translated) form AND any string characters will appear as their ASCII HEX codes (e.g., $30 is "0"). Since the whole program is tokenized, a DEBUG will appear as some hex tokens (interpreter commands), then at some point the parameters (with your string of ASCII bytes), etc.

    I understand that, and that is what I expected, but it does not explain the following program...

    ' {$STAMP BS2}
    ' {$PBASIC 2.0}
    
    DEBUG "HELLO WORLD"
    
    



    ...showing up on the memory map as...

    07E0 : 00 00 00 00 00 00 00 44 33 A6 99 D4 EC 69 76 35
    07F0 : 53 F6 34 63 9A 31 CD 8A 66 48 13 84 4C 35 07 C0
    
    



    Where is "HELLO WORLD"? I don't see it. I see an H and an L. That's all.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-11-27 21:57
    The path to understanding this is to change one character and see what changes in the memory map. If you do this enough times, you'll eventually reach the "aha!" moment. One thing to be aware of is that tokens are not byte-aligned, so the characters you're hoping to see won't be apparent in a hex dump. Here is a website that may help you.

    -Phil
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-11-30 18:20
    I will expand a little on what Phil said…When the text is part of the program the bytes are tokenized or encoded with the PBASIC tokens which, as Phil said, are not byte aligned. However, if you put your data into a DATA statement like below, you can scroll to the bottom of memory (top of map) and see the ASCII values there, since they are stored as raw byte data. I hope this helps. Take care.
    ' {$STAMP BS2}
    ' {$PBASIC 2.0}
    DATA "HELLO WORLD"
    DEBUG "HELLO WORLD"
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • GICU812GICU812 Posts: 289
    edited 2007-11-30 18:39
    try Debug "AAAAA"
    and look for the repeating character.

    Then Change it to
    Debug "ABACAD"

    etc
  • Andy FoxAndy Fox Posts: 46
    edited 2007-11-30 20:56
    GICU812 said...

    try Debug "AAAAA"
    and look for the repeating character.

    Then Change it to
    Debug "ABACAD"

    Thanks. I did this, actually. I did a DEBUG "AAAAAAAAAAAAAAAA" and still was not able to make complete sense of it. Seems there was some sort of repeating pattern every 17 bits, but the pattern of those 17 bits changed every 3 or 4 patterns (and nowhere in those 17 bits was the pattern "01000001", so I couldn't find any reasoning to it. I'm guessing it's some sort of propriatory Parallax format.

    I know I can use DATA statements, but that was not my question.
Sign In or Register to comment.