variable declaration in multi-slot BS2pe program

Hi All,
It seems common (even recommended) to declare variables in all 8 slots of a BS2pe program even if they are not specifically used in a particular slot.
Meaning, if variable XYZ is declared and only used in slot 1, it must be declared in slots 2 through 8 also.
Does anybody know why this is the case?
Thanks.
It seems common (even recommended) to declare variables in all 8 slots of a BS2pe program even if they are not specifically used in a particular slot.
Meaning, if variable XYZ is declared and only used in slot 1, it must be declared in slots 2 through 8 also.
Does anybody know why this is the case?
Thanks.
Comments
Here's an example: Say you have two word variables and a byte variable but in the next slot you only declare the byte. It will now occupy part of the original word variable and corrupt that for when you return.
...ahhh - got it!
Thanks.
Essential variables that really need to be used often in multiple banks can be allocated first in every slot. Memory is always allotted to words first in the order they are defined in the program, then all the bytes, then the nibs, then the bits.
If there are bytes, nibs and bits that need to be conserved between slots, give them an alias name as part of one of the initial words. E.g.,
myBestByte VAR myGoodWord.byte0
myBestNib VAR myGoodWord.nib3
myBestBit VAR myGoodWord.bit12
Hi Mr. Allen - yes, I just discovered this morning how variables are allocated (word, then byte, then nib, then bit); thank you.
The tip for "shuttling" variable values will probably come in handy as I re-think the construction of an 8-slot program. Up to this point, I've been lucky that cross-slot variables haven't clashed.
DJ
The trick in the way you do things is to keep track of any variables that may no longer be properly initialized after you've switched banks. I've seen many people get caught by that when declaring things differently.
Out of the 208 bits (13 X 16) available, I'm using 197 in combinations of words, bytes, nibs, nib arrays, and a single bit. Doing this even clarifies "shadowing" nib arrays (0) to other nibs.
And it adds to the documentation that I should have done at the beginning...shame on me :frown:
Hi Tom - how would you envision that looking and operating?
' {$STAMP BS2px, Fonts.bpx, Adjust.bpx, Pithy.bpx, Pithy2.bpx, Pithy3.bpx, Pithy4.bpx, Days.bpx} ' {$PBASIC 2.5} ' {$PORT COM1} Days DATA "SunMonTueWedThuFriSat" Months DATA "JanFebMarAprMayJunJulAugSepOctNovDec" '++++++++++++++++define the program modules++++++++++ Main CON 0 Fonts CON 1 Adjust CON 2 Pith CON 3 '+++++++++++++RAM+++++++++++++++++ RCols CON 0 'first 64 bytes are the pattern buffer FlagWord VAR Word 'must be the first in every module FlagByte VAR FlagWord.LOWBYTE FlagNib VAR FlagByte.LOWNIB Started VAR Flagnib.BIT0 '1 says we been through initialization Pithy VAR FlagNib.BIT1 'get font to display a pithy saying NoBD VAR FlagNib.BIT2 'no birthday boy DST VAR FlagNib.BIT3 'daylight saving time in effect Lite VAR FlagByte.HIGHNIB 'current brightness variable HB VAR Flagword.HIGHBYTE 'high byte PPnt VAR HB.HIGHNIB 'which module contains the saying Quick VAR HB.LOWNIB 'throttle TWord0 VAR Word Secs VAR TWord0.HIGHBYTE 'BCD Seconds Mins VAR TWord0.LOWBYTE 'BCD Minutes TWord1 VAR Word Hrs VAR TWord1.HIGHBYTE 'BCD Hours Day VAR TWord1.LOWBYTE 'BCD Day of week TWord2 VAR Word Date VAR TWord2.HIGHBYTE 'BCD Date of month Month VAR TWord2.LOWBYTE 'BCD Month Saying VAR TWord2 'contains the address of the current saying. Reuses Date/Month TWord3 VAR Word Year VAR TWord3.HIGHBYTE 'BCD Year Fahr VAR TWord3.LOWBYTE 'Bin temperature Point VAR Word IPnt VAR Point.HIGHBYTE 'ram input pointer OPnt VAR Point.LOWBYTE 'ram output pointer RNum VAR Word 'random saying selector 'from here down is local to each module WVar VAR Word 'generally useful word varialbe BVar VAR Byte Dat VAR Byte 'data to/from clock i VAR Byte j VAR Byte Device VAR Byte Column VAR Byte Col16 VAR Column.LOWNIB 'low order bits of column Color VAR Byte Adrs VAR Byte Pattern VAR Byte begin: IF (Started = 0) THEN GOTO StartUp 'need to go initialize the world
Note that the first half-dozen or words of the variable area needs to be identical for all modules. It would be nice to move that to a separate file, say IDECLARE.bpx which is called by each module (including this one). Then to make a change, one would merely make it in IDECLARE. Just saves a little bookkeeping. But I think that Parallax would have done this about ten years ago if it was gonna happen.
OK - I understand what you're saying. Any, yeah, it would have been done initially if done at all.
Later,
DJ
More questions concerning variables - this time the order in which they are placed in the variable space.
Given:
' {$STAMP BS2pe} ' {$PBASIC 2.5} j VAR Byte k VAR Byte n_ary VAR Nib(3) bt1 VAR Bit bt2 VAR Bit bt3 VAR Bit END
Are the variables inserted into the variable register(s) as shown below?
Thanks much.
Yup - I was aware of the register display in the IDE, just not sure if the example "j" and "k" were inserted in the order specified by the code ("j" declared first, then "k").
I could tell from the IDE display the order in which word/byte/nib/bit variables were allocated but didn't know if arrays were inserted starting with index zero.
Thanks again.
...roger that.