Shop OBEX P1 Docs P2 Docs Learn Events
Array of alliases in spin posible? — Parallax Forums

Array of alliases in spin posible?

Rick_HRick_H Posts: 116
edited 2011-10-05 20:51 in Propeller 1
I have 4 cogs of assembly that all read and write to the hub memory, in the hub thier organized by thier usage from the ASM code but in spin I would like to loop through sets of the variables to pass in groups.

just as an example
var
word     array1[8], array2[8], array3[6], array4[6], array7[6], array8[8]


in the spin module their declared in I would like to be able to to write to the first element of each array in an indexed loop. so I would have 6 arrays containing 1 element each from the arrays ect.

is this possible? or is their an easier way to do this? keep in mind their not completely organized in this way their are vars randomly in between them for other purposes, I know I could just do loops with steps with this var grouping.

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-10-05 20:36
    You could sort of do this (if I understand what you're asking correctly).

    Here's what I'm thinking.
    DAT
     
    masterArray               word @array1, @array2, @array3, @array4, {
                            }    @array5, @array6, @array7, @array8
    

    The address with be off (I think by 10). You can correct for this.
    correction := @array1 - masterArray[0]
    

    The to write a 5 to the first element of each array.
    repeat index from 0 to 7
        word[masterArray[index] + correction] := 5
    

    I think that's the way it would work.

    I'm not sure I understood what you were asking so sorry if I'm way off base.

    Hopefully someone here will have a better way of doing this (they usually do).

    Duane
  • Rick_HRick_H Posts: 116
    edited 2011-10-05 20:42
    Basicaly I have a set of 10 arrays declared in a var block of spin, it holds the addresses to all my PASM code and all the data thats passed back and forth, I just wrote code to transmit some of the elements of the arrays to a VB application, but its a lot of coding to access them in the right order as their organized for the PASM routines not the spin code. so when VB writes to my micro it will let spin know what group of parameters I am writing to.
  • AribaAriba Posts: 2,690
    edited 2011-10-05 20:46
    You can initialze a alias (or master-) array once with the addresses of your arrays and then access theme with word[]:
    long alias[6]
    
    PUB
      alias[0] := @array1[0]        'initialize alias array
      alias[1] := @array2[0]
      ..
      alias[5] := @array8[0]
    
      repeat i from 0 to 3          'index i in array
        repeat n from 0 to 5        'array n
          word[alias[n]][i] := n*i  'write something
    

    Andy
  • Rick_HRick_H Posts: 116
    edited 2011-10-05 20:51
    yes, thats exactly what I was looking for, thanks Andy.
Sign In or Register to comment.