Shop OBEX P1 Docs P2 Docs Learn Events
Memory block transfer — Parallax Forums

Memory block transfer

nrandalnrandal Posts: 5
edited 2010-11-04 18:55 in Propeller 1
I was attempting to transfer a block of memory values from one cog to another. I was expecting my VAR variables to be kept in order by they are optimized and grouped into similar structure.

Say I was going to transfer 1 long, 2 words and 8 bytes from by source cog to the calling cog, I was hoping to do a longmove(dst, src, 3) but that doesn't work.

Is there a way to force VAR to not reorganize variables in memory? Is there another way I should be doing this?

Do I need to pass in the start address for my long, word and byte values? 3 memory address variables isn't bad but would be nice to do it with 1.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-11-04 11:11
    VAR will always reorder the variables in the object with the longs first, words second and bytes last. There's no way to disable this.

    You can declare variables using a DAT section and that will maintain the order that you define like:

    var1 byte 0
    var2 byte 0
    var3 word 0
    var4 long 0

    Note that the compiler will properly align the different sizes adding padding bytes as needed if you don't keep them aligned to the right boundaries.

    You can access different subportions of variables like this:

    var4.word[0]
    var4.word[1]
    var4.byte[3]

    Remember that the move operations require addresses, so you'd need

    LONGMOVE(@dst, @src, 3)

    where "dst" is the name of the destination variable(s) and "src" is the name of the source variable(s).
  • mparkmpark Posts: 1,305
    edited 2010-11-04 18:42
    nrandal wrote: »
    I was attempting to transfer a block of memory values from one cog to another... Say I was going to transfer 1 long, 2 words and 8 bytes from by source cog to the calling cog...

    Longmove and its ilk don't move data from one cog to another.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-11-04 18:55
    mpark wrote:
    Longmove and its ilk don't move data from one cog to another.
    Strictly speaking, this is true. Such commands only shuttle data from one hub location to another. (Actually, the source data is transferred into the cog executing the move, then back out to the new destination location.) However, because various Spin cogs "own" certain blocks of hub data, the illusion that these commands can transfer data cog-to-cog can, nonetheless, be a useful abstraction.

    -Phil
Sign In or Register to comment.