View Full Version : Spin Arrays
09-07-2007, 02:54 AM
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.
09-07-2007, 03:27 AM
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.
09-07-2007, 04:22 AM
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[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[x][y]", you have to use something like LONG[arr[x]][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"
09-07-2007, 06:09 AM
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.