BS2 Fixed variables
Joseph Osborne
Posts: 13
I am trying to modify the Scribbler include program. It uses all fixed variables and seems to use all the variable memory. I want to change some variables, to do a DO WHILE loop, for instance, but find the counter gets overwritten. Obviously I don't understand something important.
I am looking for a technical discussion of how the BS2 stores fixed variables. I can't find anything in the manual. Can anyone point me to a technical manual or something similar?
Thanks,
Joseph Osborne
PS- my hat is off to Phil Pilgrim who wrote this amazing program.
I am looking for a technical discussion of how the BS2 stores fixed variables. I can't find anything in the manual. Can anyone point me to a technical manual or something similar?
Thanks,
Joseph Osborne
PS- my hat is off to Phil Pilgrim who wrote this amazing program.
bs2
7K
Comments
Generally having an allocation scheme to help you track variables is a good idea. In my own program is use ascending variable names ACC, X, Y, Z. ACC is the most volatile and Z is the least volatile. In this code it looks like it is using numbered counter variables for similar purposes.
Mike, somebody slipped carbon paper under your keyboard as you're in triplicate!
Example VAR W0
Example2 VAR Example.HIGHBYTE
Vs
Example VAR WORD
Example2 VAR Example.HIGHBYTE
Will it allocate the same space for Example2?
Joseph Osborne
Here's a quick answer to your question. B0 and B1 are contained within W0's low byte and high byte respectively. In your first example you are creating an alias to W0 and then creating an alias to its high byte. This explicitly uses memory location W0 for storage. In your second example you are relying on PBASIC to choose which word memory location to allocate for Example and then creating an alias for Example2 in the high byte. Which location PBASIC chooses depends upon the other variables defined by the program and their order.
I prefer the second style of memory allocation because it lets PBASIC do all the jiggery-pokery so I can concentrate on program logic.
"...for all BS2 models, fixed variables like B3 and W1 and any aliases do not show up on the memory map as memory used. The editor ignores fixed variables when it arranges automatically allocated variables in memory. Remember, fixed and allocated variables can overlap."
This is what concerns me. If I use even one fixed variable, do I need to allocate the whole memory map to avoid unpleasant surprises? I am thinking I need to convert the whole list of declarations away from fixed unless I understand exactly how the compiler works.