PDA

View Full Version : Memory block transfer



nrandal
11-04-2010, 06:02 PM
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.

Mike Green
11-04-2010, 06:11 PM
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).

mpark
11-05-2010, 01:42 AM
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)
11-05-2010, 01:55 AM
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