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?
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]".
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
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)"
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.
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.
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).
Comments
Instead, I'd use
EDIT: Curse you Mike Green!
EDIT #2: Is it faster to loop by hand? Is longmove faster than bytemove or wordmove?
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
IF array1 == array2
Then you could write "if compare(@array1,@array2,12)"
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 Baker
Propeller Applications Engineer
Parallax, Inc.