Shop OBEX P1 Docs P2 Docs Learn Events
Array with b5, b6, b7....b15 — Parallax Forums

Array with b5, b6, b7....b15

ArchiverArchiver Posts: 46,084
edited 2002-04-02 21:54 in General Discussion
Hi Group
It is probably an easy Question but I don' see the answer:

How con I declare an array "manually"?
Instead of :
"Temp var byte(10)"

I would like to say something like:
"Temp var ....b5 to b15..."

to tell the compiler to use location b5 to b15
(for easy use in multiple slots)

and my update-loop below should still work
Thankful for an answer
Regards, Heinz Schwenk Germany


Temp var byte(10)

update:
for loop=9 to 1
Temp(loop)=Temp(loop-1) 'Temp0=newTemp, Temp1=Temp0 ,
Temp2=Temp1,......
Debug ? loop, ? Temp(loop)
next
Pause 2000
goto update

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-03-30 18:12
    You can't declare an array of [noparse][[/noparse]internal] PBASIC variable names and you don't
    have to since PBASIC memory works as an array anyway. Let me say first that
    I STRONGLY recommend you NOT using internal variable names -- I believe it's
    better to delcare an array as you need it and let the compiler organize the
    variable RAM.

    That said, you can access P5 .. P15 with a simple pointer, indexed from B0

    pntr VAR Nib

    ' clear the array
    FOR pntr = 5 TO 15
    B0(pntr) = 0
    NEXT

    ' or like this:
    FOR pntr = 0 TO 10
    B5(pntr) = 0
    NEXT


    -- Jon Williams
    -- Parallax


    In a message dated 3/30/02 3:54:09 AM Central Standard Time, hschwenk@g...
    writes:


    > Hi Group
    > It is probably an easy Question but I don' see the answer:
    >
    > How con I declare an array "manually"?
    > Instead of :
    > "Temp var byte(10)"
    >
    > I would like to say something like:
    > "Temp var ....b5 to b15..."
    >
    > to tell the compiler to use location b5 to b15
    > (for easy use in multiple slots)
    >
    > and my update-loop below should still work
    > Thankful for an answer
    > Regards, Heinz Schwenk Germany
    >
    >
    > Temp var byte(10)
    >
    > update:
    > for loop=9 to 1
    > Temp(loop)=Temp(loop-1) 'Temp0=newTemp, Temp1=Temp0 ,
    > Temp2=Temp1,......
    > Debug ? loop, ? Temp(loop)
    > next
    > Pause 2000
    > goto update
    >




    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2002-03-30 19:55
    Thanks Jon,
    I understand this:

    FOR pntr = 0 TO 10
    B5(pntr) = 0
    NEXT

    But w h e y not using internal variable names --
    > I STRONGLY recommend you NOT using internal variable names --
    If I use and change "global Variables" in different slots
    I don't need to think about saving them al the time ?
    What is the disadvantage of using internal variable names?
    I may don't see the point ?

    Have a nice and happy easter,

    Thanks Heinz Germany



    > You can't declare an array of [noparse][[/noparse]internal] PBASIC variable names and you don't
    > have to since PBASIC memory works as an array anyway. Let me say first that
    > I STRONGLY recommend you NOT using internal variable names -- I believe it's
    > better to delcare an array as you need it and let the compiler organize the
    > variable RAM.
    >
    > That said, you can access P5 .. P15 with a simple pointer, indexed from B0
    >
    > pntr VAR Nib
    >
    > ' clear the array
    > FOR pntr = 5 TO 15
    > B0(pntr) = 0
    > NEXT
    >
    > ' or like this:
    > FOR pntr = 0 TO 10
    > B5(pntr) = 0
    > NEXT
    >
    >
    > -- Jon Williams
    > -- Parallax
    >
    >
    > In a message dated 3/30/02 3:54:09 AM Central Standard Time, hschwenk@g...
    > writes:
    >
    >
    > > Hi Group
    > > It is probably an easy Question but I don' see the answer:
    > >
    > > How con I declare an array "manually"?
    > > Instead of :
    > > "Temp var byte(10)"
    > >
    > > I would like to say something like:
    > > "Temp var ....b5 to b15..."
    > >
    > > to tell the compiler to use location b5 to b15
    > > (for easy use in multiple slots)
    > >
    > > and my update-loop below should still work
    > > Thankful for an answer
    > > Regards, Heinz Schwenk Germany
    > >
    > >
    > > Temp var byte(10)
    > >
    > > update:
    > > for loop=9 to 1
    > > Temp(loop)=Temp(loop-1) 'Temp0=newTemp, Temp1=Temp0 ,
    > > Temp2=Temp1,......
    > > Debug ? loop, ? Temp(loop)
    > > next
    > > Pause 2000
    > > goto update
    > >
    >
    >
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and Body
    of the
    message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-03-30 22:47
    In a message dated 3/30/02 1:55:51 PM Central Standard Time, hschwenk@g...
    writes:


    > But w h e y not using internal variable names --
    >
    Because, depending on the complexity of your program and other variable
    definitions, using internal variable names can lead to conflicts and
    inefficient memory use.

    B0 .. B25 (W0 .. W12) are PHYSICAL locations in the Stamp's memory. Do you
    really care where your variables are located? The only time I suggest using
    internal names is when you want to clear all variables in the middle of a
    program. You can do it like this:

    FOR W12 = 0 TO 11
    W0(W12) = 0
    NEXT
    W12 = 0

    -- Jon Williams
    -- Parallax


    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2002-04-01 06:27
    >How con I declare an array "manually"?
    >Instead of :
    > "Temp var byte(10)"
    >
    >I would like to say something like:
    > "Temp var ....b5 to b15..."
    >
    >to tell the compiler to use location b5 to b15
    >(for easy use in multiple slots)

    Hi Heinz ,

    Like Jon, I prefer to let the compiler allocate space for the
    variables, rather than using the predefined variables. As you know
    already, it is more of a problem when you have a multibank stamp with
    its multiple program slots. No matter how you do it, it takes
    planning.

    One trick is to realize that the compiler always allocates space to
    word variables first, before any of the bytes, nibs or bits.
    Therefore, to have everything come out in a set place, you can define
    all of your "globals" as words. You have to define them first in
    every slot. Furthermore, if you need (probably) "global" bytes, nibs
    and bits, you have to define them as aliases within those words so
    that they too will come out in the "protected" space. The beauty of
    that is, that _after_ the "globals" within each individual slot, you
    can proceed to define as many "local" words, bytes, nibs and bits as
    you need and they will not overlap the "protected" variables.

    For example, if you have a "global" array that takes 11 bytes, and 1
    global nib and 4 "global flag" bits, you could define the following 6
    word variables in every slot:

    glob0 var word
    glob1 var word
    glob2 var word
    glob3 var word
    glob4 var word
    glob5 var word
    crunch var glob0.byte0 ' for 11 byte array addressed as crunch(i)
    i var glob5.nib2 ' nibble for global index
    flags var glob5.nib3 ' nibble for global flag bits
    flag0 var flags.bit0 ' a flag bit and so on

    Then you can define any "local" variables you want _after_ those globals:
    tempword var word
    temp var byte(10)
    tempbi var bit

    I have some more info on my techniques with the multibank stamps at
    http://www.emesystems.com/BS2SX.htm



    -- regards,
    Tracy Allen
    electronically monitored ecosystems
    mailto:tracy@e...
    http://www.emesystems.com
  • ArchiverArchiver Posts: 46,084
    edited 2002-04-02 21:54
    Hi Tracy,
    Thanks a lot, it's nice to get these detailed answers **!!!
    regards Heinz


    > >How con I declare an array "manually"?
    > >Instead of :
    > > "Temp var byte(10)"
    > >
    > >I would like to say something like:
    > > "Temp var ....b5 to b15..."
    > >
    > >to tell the compiler to use location b5 to b15
    > >(for easy use in multiple slots)
    >
    > Hi Heinz ,
    >
    > Like Jon, I prefer to let the compiler allocate space for the
    > variables, rather than using the predefined variables. As you know
    > already, it is more of a problem when you have a multibank stamp with
    > its multiple program slots. No matter how you do it, it takes
    > planning.
    >
    > One trick is to realize that the compiler always allocates space to
    > word variables first, before any of the bytes, nibs or bits.
    > Therefore, to have everything come out in a set place, you can define
    > all of your "globals" as words. You have to define them first in
    > every slot. Furthermore, if you need (probably) "global" bytes, nibs
    > and bits, you have to define them as aliases within those words so
    > that they too will come out in the "protected" space. The beauty of
    > that is, that _after_ the "globals" within each individual slot, you
    > can proceed to define as many "local" words, bytes, nibs and bits as
    > you need and they will not overlap the "protected" variables.
    >
    > For example, if you have a "global" array that takes 11 bytes, and 1
    > global nib and 4 "global flag" bits, you could define the following 6
    > word variables in every slot:
    >
    > glob0 var word
    > glob1 var word
    > glob2 var word
    > glob3 var word
    > glob4 var word
    > glob5 var word
    > crunch var glob0.byte0 ' for 11 byte array addressed as crunch(i)
    > i var glob5.nib2 ' nibble for global index
    > flags var glob5.nib3 ' nibble for global flag bits
    > flag0 var flags.bit0 ' a flag bit and so on
    >
    > Then you can define any "local" variables you want _after_ those globals:
    > tempword var word
    > temp var byte(10)
    > tempbi var bit
    >
    > I have some more info on my techniques with the multibank stamps at
    > http://www.emesystems.com/BS2SX.htm
    >
    >
    >
    > -- regards,
    > Tracy Allen
    > electronically monitored ecosystems
    > mailto:tracy@e...
    > http://www.emesystems.com
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and Body
    of the
    message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
Sign In or Register to comment.