Shop OBEX P1 Docs P2 Docs Learn Events
Spin Arrays — Parallax Forums

Spin Arrays

mynet43mynet43 Posts: 644
edited 2007-09-06 23:09 in Propeller 1
Is there a way to declare a two dimensional array in SPIN?

I want to do some matrix arithmetic and this would make it easier.

I couldn't find anything in the manual.

The obvious: long phi doesn't seem to work.

Is there a way to do this or do I have to declare it single dimensioned and then play with the index?

Thanks for your help.

Jim

Comments

  • BergamotBergamot Posts: 185
    edited 2007-09-06 20:27
    There's no reason that I can see why you couldn't make an array of arrays, i.e. an array filled with pointers to other arrays.

    The indexing method is more time/space efficient though, at the cost of code complexity.
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-06 21:22
    The word "array" in SPIN is a misnomer, there are no arrays but vectors of memory cells only. So you have to reinvent one of the well-known three kinds of array implementations, as every assembly language programmer:
    - brute force multiplication pos = x*ysize +y (or y*xsize+x - you have the choice)
    - intermediate addressvector (preset: arr[noparse][[/noparse]x]:= @arrspace*x*ysize
    - sparse matrices using bitvectors, well above this thread I guess...

    Alas, there is no such thing as this practical denotation "arr[noparse]/noparse]x][noparse][[/noparse]y]", you have to use something like LONG[noparse][[/noparse]arr[noparse][[/noparse]x[noparse][[/noparse]y]

    And don't get confused with longs, words, or bytes...
    Note that the LONG I use has nothing to do with the sizing of the "arr" address vector (which could be WORDs as well), but with the size of your element in "arrspace"
  • mynet43mynet43 Posts: 644
    edited 2007-09-06 23:09
    Thanks for the quick answers. That's what I was afraid of.

    I know how to do it, it's just a little trickier to debug.

    Jim
Sign In or Register to comment.