i am new to PBASIC and BasicStamps. I am using BS2p.
How to pass variables to/from subroutines in PBASIC?
Are there any distinction between global and local variables in
PBASIC?
Thanks
In a message dated 5/7/2003 3:45:27 PM Central Standard Time, mohammedrasiq@y... writes:
> i am new to PBASIC and BasicStamps. I am using BS2p.
> How to pass variables to/from subroutines in PBASIC?
> Are there any distinction between global and local variables in
> PBASIC?
> Thanks
[noparse][[/noparse]Non-text portions of this message have been removed]
All variables are GLOBAL. In the BS2, they are
actually registers on the chip.
So, typically you'll have one or more interface variables
for your subroutines. You'll set the variable, call
the subroutine (which can change the variable) and
then examine or use the variable's returned value.
You can conserve variable space by defining a few
'Temp1 VAR BYTE', 'Temp2 VAR BYTE' vars, and then
ONLY using them as temporary variables inside
subroutines (when your subs need a temp var).
I've sometimes assigned 2 leading characters to my
variables, to provide a pseudo 'namespace'. With
the BS2 this is of limited value, since you want
to reuse the limited register space.
--- In basicstamps@yahoogroups.com, "mohammedrasiq"
<mohammedrasiq@y...> wrote:
> i am new to PBASIC and BasicStamps. I am using BS2p.
> How to pass variables to/from subroutines in PBASIC?
> Are there any distinction between global and local variables in
> PBASIC?
> Thanks
Thanks Allan for your explanation. That was helpful!!
--- In basicstamps@yahoogroups.com, "Allan Lane" <allan.lane@h...>
wrote:
> All variables are GLOBAL. In the BS2, they are
> actually registers on the chip.
>
> So, typically you'll have one or more interface variables
> for your subroutines. You'll set the variable, call
> the subroutine (which can change the variable) and
> then examine or use the variable's returned value.
>
> You can conserve variable space by defining a few
> 'Temp1 VAR BYTE', 'Temp2 VAR BYTE' vars, and then
> ONLY using them as temporary variables inside
> subroutines (when your subs need a temp var).
>
> I've sometimes assigned 2 leading characters to my
> variables, to provide a pseudo 'namespace'. With
> the BS2 this is of limited value, since you want
> to reuse the limited register space.
>
>
> --- In basicstamps@yahoogroups.com, "mohammedrasiq"
> <mohammedrasiq@y...> wrote:
> > i am new to PBASIC and BasicStamps. I am using BS2p.
> > How to pass variables to/from subroutines in PBASIC?
> > Are there any distinction between global and local variables in
> > PBASIC?
> > Thanks
Comments
How to pass variables to/from subroutines in PBASIC?
Are there any distinction between global and local variables in
PBASIC?
Thanks
-- Jon Williams
-- Parallax
In a message dated 5/7/2003 3:45:27 PM Central Standard Time,
mohammedrasiq@y... writes:
> i am new to PBASIC and BasicStamps. I am using BS2p.
> How to pass variables to/from subroutines in PBASIC?
> Are there any distinction between global and local variables in
> PBASIC?
> Thanks
[noparse][[/noparse]Non-text portions of this message have been removed]
actually registers on the chip.
So, typically you'll have one or more interface variables
for your subroutines. You'll set the variable, call
the subroutine (which can change the variable) and
then examine or use the variable's returned value.
You can conserve variable space by defining a few
'Temp1 VAR BYTE', 'Temp2 VAR BYTE' vars, and then
ONLY using them as temporary variables inside
subroutines (when your subs need a temp var).
I've sometimes assigned 2 leading characters to my
variables, to provide a pseudo 'namespace'. With
the BS2 this is of limited value, since you want
to reuse the limited register space.
--- In basicstamps@yahoogroups.com, "mohammedrasiq"
<mohammedrasiq@y...> wrote:
> i am new to PBASIC and BasicStamps. I am using BS2p.
> How to pass variables to/from subroutines in PBASIC?
> Are there any distinction between global and local variables in
> PBASIC?
> Thanks
--- In basicstamps@yahoogroups.com, "Allan Lane" <allan.lane@h...>
wrote:
> All variables are GLOBAL. In the BS2, they are
> actually registers on the chip.
>
> So, typically you'll have one or more interface variables
> for your subroutines. You'll set the variable, call
> the subroutine (which can change the variable) and
> then examine or use the variable's returned value.
>
> You can conserve variable space by defining a few
> 'Temp1 VAR BYTE', 'Temp2 VAR BYTE' vars, and then
> ONLY using them as temporary variables inside
> subroutines (when your subs need a temp var).
>
> I've sometimes assigned 2 leading characters to my
> variables, to provide a pseudo 'namespace'. With
> the BS2 this is of limited value, since you want
> to reuse the limited register space.
>
>
> --- In basicstamps@yahoogroups.com, "mohammedrasiq"
> <mohammedrasiq@y...> wrote:
> > i am new to PBASIC and BasicStamps. I am using BS2p.
> > How to pass variables to/from subroutines in PBASIC?
> > Are there any distinction between global and local variables in
> > PBASIC?
> > Thanks