Shop OBEX P1 Docs P2 Docs Learn Events
Variables and RUN statement — Parallax Forums

Variables and RUN statement

ScottLScottL Posts: 14
edited 2006-06-19 01:30 in BASIC Stamp
I am having a difficult time getting my head around page 382 in the syntax manual. I thought the only way to share variables was to GET and PUT them to scratch pad RAM. I understand that BS2 stores word length variables first but why can slot 1 see them if they are not passed? What am I missing? -Scott

Comments

  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-06-17 16:43
    All the slots see the same set of variables, electrically speaking. The first word in RAM for slot zero is also the first word in in every other slot. The trick is in naming. If the first word variable in the slot 0 program is "cat" and the first word defined in slot 1 is "dog", then when you execute RUN 1, then dog is actually the same theng as cat, as they refer to the same physical location in RAM. In programs, when you want to pass information via RAM, you will generally use the same variable names in the same order in both slots.

    GET and PUT provide another way to pass variables around, available on all of the multibank Stamps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-17 18:19
    Hello,

    ·· You can also check out the following Nuts & Volts article on Multi-Bank Programming, which may prove insightful.· I hope this helps.· Take care.

    http://www.parallax.com/dl/docs/cols/nv/vol3/col/nv87.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • ScottLScottL Posts: 14
    edited 2006-06-18 23:05
    So, may I assume that any shared variables must be at the beginning of the declarations in each slot's program·and must be in the same order and in word, byte, nibble, bit sequence? -Scott
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-06-18 23:40
    Scotti -

    EXACTLY so! In fact, is often easisest to use the Stamp Editor's COPY and PASTE facility to ensure that all banks are the same. That's NOT to say if you had some compelling reason to do so, you couldn't then change the names of certain of the variables, if different names would make more sense in the "other" bank(s). The order and the size are the two important characteristics, as the variable names are not brought forward (internally) at all.

    The following is just an advanced tip, so if you're new to PBASIC, it can be totally ignored. Others may find it interesting or useful.

    In order to make the best use of RAM storage, the PBASIC Editor/Interpreter will always force the order of the variables (VAR statement) in allocated RAM memory according to SIZE. Thus, all WORD sized variables will be allocated in available RAM storage first, and before any BYTE sized variables. All Byte sized variables will be allocated storage before any NIB variables. And finally, all NIB sized variables will be allocated storage before any BIT sized variables. Just as an additional sidenote NO STORAGE is allocated for user defined CONSTANTS (CON statement).

    So, when you look at the PBASIC Editor's Memory Map, the order you see will be the ACTUAL memory assignments, and they may NOT be in the order you have assigned them, unless you used the same rules for variable assignment.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • ScottLScottL Posts: 14
    edited 2006-06-19 00:35
    Thanks Bruce! Maybe Jon (in his Nuts and Volts column) was demonstrating the use or the GET / PUT method of passing variables. It sure seems like a difficult way to do it if the variable space is shared. With 8 slots·worth of programs·variable space could become a problem. -Scott

    p.s.·I like the "Scotti" thang I may use it for an alias sometime! Computer alias that is.tongue.gif Why don't they have a "Dumb A**" emoticon? Once I comprehend something I marvel at how dense I was.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-06-19 01:30
    For the reasons that Bruce described, I always declare the cross-bank variables as words, and any keeper bytes, nibs or bits are aliased within those first few words. For example, I set aside one word as a variable, "flags" :
    flags VAR Word
     minuteRoll VAR flags.bit0
     lineFeed VAR flags.bit1
     firstInit VAR flags.bit2
    


    That is defined as one of the first words in every slot, along with other important pointers. Also there can be nib and byte size variables and pointers, and those can also be defined as aliases within the first few words in every bank.

    The avantage of using alias names within words is that all the really important keeper variable can be concentrated at the top of memory in the primary allocation, and you can leave the rest of the words, bytes, nibs and bits free for local use within each individual slot without concern for order. If you just go and define a bit as a Bit, standalone, then as Bruce pointed out it will be allocated space after all the words, bytes and nibs, so then you are forced to align _all_ of the variables, keepers or not, instead of just the words. Be sure you get familiar with the alias name capabiltiy of the Stamp! The whole RAM memory is an array common to all the slots. Very powerful.

    I make heavy use of the scratchpad and the eeprom. The RAM holds the pointers.

    Another take on multibank programming is www.emesystems.com/BS2SX.htm.

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