PBASIC: Temporary / Frame Variables?
Archiver
Posts: 46,084
I'm programming a BS2SX for my son's BattleBot. When I first wrote
the code I declared two temporary varibles inside the "MainLoop:"
called "temp1 VAR byte" and "temp2 VAR byte". I used this approach
because I wanted to not use up the 26 allowed variables according to
the ISSAC16 (robot controller that uses the BS2SX. I'm more of
a "C" programmer and it's been a long time since I wrote any code.
The Bot is not completely working properly, and programming
iterations are difficult to do due to a design flaw that requires me
to take apart to the robot to blow new code into the BS2SX -
otherwise I could probably answer my question with a couple
programming iterations.
Again, the specific question "Does PBASIC allow the use of
frame/temporary variables, or do you think that this might be
trouble - the code tokenizes successfully, and the Bot does operate -
I'm just getting some limited unexpected results"
Thanks,
Bob Jacoby
Team V
KillerV (the Bot)
BattleBeach.com (the competition)
the code I declared two temporary varibles inside the "MainLoop:"
called "temp1 VAR byte" and "temp2 VAR byte". I used this approach
because I wanted to not use up the 26 allowed variables according to
the ISSAC16 (robot controller that uses the BS2SX. I'm more of
a "C" programmer and it's been a long time since I wrote any code.
The Bot is not completely working properly, and programming
iterations are difficult to do due to a design flaw that requires me
to take apart to the robot to blow new code into the BS2SX -
otherwise I could probably answer my question with a couple
programming iterations.
Again, the specific question "Does PBASIC allow the use of
frame/temporary variables, or do you think that this might be
trouble - the code tokenizes successfully, and the Bot does operate -
I'm just getting some limited unexpected results"
Thanks,
Bob Jacoby
Team V
KillerV (the Bot)
BattleBeach.com (the competition)
Comments
> ...Again, the specific question "Does PBASIC allow the use of
> frame/temporary variables...
In a word: no. Any variables declared anywhere within a single
PBASIC program (including its subroutines) are always active and
consume variable space--their "scope" and "lifetime" are universal
and unlimited.
The simplest solution on your BS2SX might be to use the 63 free bytes
of scratchpad memory to save/restore variables. See the GET and PUT
instructions in the manual for more info.
Regards,
Steve
> frame/temporary variables, or do you think that this might be
> trouble - the code tokenizes successfully, and the Bot does
operate -
> I'm just getting some limited unexpected results"
PBasic uses the 13 word-sized (16 bit) registers of the chip for VAR
variables. To its advantage, you can declare them BIT, NIB, BYTE, or
WORD, and only the bits declared are used out of the registers. That
means you can have 13 WORD vars, 26 BYTE vars, or 52 NIB vars, or 208
BIT vars, or any combination using less than 208 bits.
And yes, ALL 'VARS' are GLOBAL. Being a 'C' programmer myself,
that's a pain. (Note PBasic is also NOT case sensitive -- if that
helps). Note CON declarations take up NO VAR space, they are simply
copied into place at compile time. Note comments take up no space
either, they are ignored at compile time. And oh, yes, you're only
allowed 8 nested levels of 'GOSUB'.
The 'Memory Map' part of the Editor shows what you've used and what's
available, both in the EEPROM and the Ram Map (aka Registers, aka VAR
space).
The result of all of this is it allows you (the programmer) very
efficient use of limited resources, once you know how it works.
If you can show me your code I may give some hints about how to
make efficient use of RAM. I am pretty sure that using the
scratchpad ram is not the solution to your problem unless you really
need a lot of RAM.
Regards
Adrian
them and even give the same variable [noparse][[/noparse]location] different names for different
sections of your program [noparse][[/noparse]to make the code more readable]. For example:
temp VAR Byte
hits VAR temp
By doing this, 'hits' gets assigned to the same variable location as the
compiler assigned to 'temp'. Just be careful that the use of these to names
will not conflict with each other -- that is, they are both temporary and not
used at the same time.
-- Jon Williams
-- Applications Engineer, Parallax
In a message dated 3/4/2003 7:27:21 AM Central Standard Time, jacoby@f...
writes:
> Again, the specific question "Does PBASIC allow the use of
> frame/temporary variables, or do you think that this might be
> trouble - the code tokenizes successfully, and the Bot does operate -
> I'm just getting some limited unexpected results"
[noparse][[/noparse]Non-text portions of this message have been removed]