Shop OBEX P1 Docs P2 Docs Learn Events
array := array — Parallax Forums

array := array

codekingcodeking Posts: 39
edited 2007-02-01 19:36 in Propeller 1
Does the assignment operator (:=) work with arrays.· For example, we have array1 and array2.· Each one has 12 bytes.· If we do array1 := array2, will array 2's data be copied to array1?· If not, how do I do this?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-01 16:59
    The assignment operator does not work with arrays. You can use bytemove/wordmove/longmove to do a copy (look at the manual) or you can do a loop with something like "repeat i from 0 to 11", then "array1[noparse][[/noparse] i] := array2[noparse][[/noparse] i]".
  • BergamotBergamot Posts: 185
    edited 2007-02-01 17:02
    I think the assignment operator would cause both array variables to point to the same array in memory (which does not sound like what you want).

    Instead, I'd use

    bytemove(@Array1, @Array2, 12)
    



    EDIT: Curse you Mike Green! smilewinkgrin.gif

    EDIT #2: Is it faster to loop by hand? Is longmove faster than bytemove or wordmove?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-01 17:10
    Bergamot,
    If the array is word or long aligned, wordmove is faster and longmove is fastest since 2 bytes or 4 bytes are moved with two Hub accesses.
    Mike
  • codekingcodeking Posts: 39
    edited 2007-02-01 17:17
    is there some way I could do something like this?

    IF array1 == array2
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-01 17:47
    None of the operators in Spin work on arrays. You could write a subroutine (method) that takes two array addresses and compares them byte by byte and returns either true or false like:
    PRI compare(addr1,addr2,size)
       repeat size
          if byte[noparse][[/noparse]addr1++] <> byte[noparse][[/noparse]addr2++]
             return false
       return true
    
    


    Then you could write "if compare(@array1,@array2,12)"
  • codekingcodeking Posts: 39
    edited 2007-02-01 17:56
    Thanks, Mike
  • asterickasterick Posts: 158
    edited 2007-02-01 19:21
    Mike Green said...
    Bergamot,
    If the array is word or long aligned, wordmove is faster and longmove is fastest since 2 bytes or 4 bytes are moved with two Hub accesses.
    Mike

    Do RD{WORD|LONG} require that they be on their appropriate boundaries? the docs don't say anything about that.
  • BergamotBergamot Posts: 185
    edited 2007-02-01 19:30
    asterick said...
    Mike Green said...
    Bergamot,
    If the array is word or long aligned, wordmove is faster and longmove is fastest since 2 bytes or 4 bytes are moved with two Hub accesses.
    Mike

    Do RD{WORD|LONG} require that they be on their appropriate boundaries? the docs don't say anything about that.

    I think he meant that it's faster if the words/longs are properly aligned, but works (though more slowly) if they are not.

    Regardless, the docs don't seem to address that issue either.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-02-01 19:35
    Any WORD|LONG operation works on aligned boundries only, the Propeller masks out bits of the address to ensure this (last LSB for WORD, last two LSB for LONG).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • asterickasterick Posts: 158
    edited 2007-02-01 19:36
    Good to know. *scampers off to fix a bug in gear*
Sign In or Register to comment.