Shop OBEX P1 Docs P2 Docs Learn Events
A better way to share data between SPIN and ASM — Parallax Forums

A better way to share data between SPIN and ASM

dnaddordnaddor Posts: 26
edited 2009-01-09 18:41 in Propeller 1
Hi y'all.

I've never liked how I shared data between SPIN and ASM. I often have lots of different sized structures, and it is too easy to make a mistake in the offsets (like forgetting to multiply by 4). I prefer to access all variables by name.

Today, I figured out an easy way to do this. The "trick" is to have a DAT section with this line:

Memory long @Memory

and then start a cog with this:

COGSTART(@CogThread, @Memory - Memory)

Now in ASM, you can access data easily by using PAR and adding the offset to the variable.

I included a simple test program. All it does is print 100+200=300.

Comments

  • mparkmpark Posts: 1,305
    edited 2009-01-09 00:24
    Clever!
  • KyeKye Posts: 2,200
    edited 2009-01-09 00:24
    This is much better:

    long Something

    PUB

    SomethingAddress := @Something

    cognew(@entry,0)

    DAT

    entry
    ....

    somethingAddress long 0


    The idea is that you embed the addresses of all the data you want to acess into the image for the cog to run. Once this is done you can simply use the addresses in getting data.

    As in:

    rdlong buffer, somethingAddress

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • KyeKye Posts: 2,200
    edited 2009-01-09 00:27
    And, how are you even doing that? The compilier usually flags that as an error if you put the "@" symbol in a dat section.

    Did they release a new version?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • dnaddordnaddor Posts: 26
    edited 2009-01-09 01:57
    The reason I don't use:

    long Something

    PUB

    SomethingAddress := @Something

    cognew(@entry,0)

    DAT

    entry
    ....

    somethingAddress long 0

    is because it gets tedious when you have lots of variables:

    DAT

    EntryNumber long 0
    HashIndex long 0
    ImJustAByte byte 0
    BigTable long 0 [noparse][[/noparse]16]
    :

    I would have to create a second variable for the address of each of these. I would have to create an assignment for each of these. With my method, I only have one copy of each variable. I also don't waste any additional RAM.
  • jazzedjazzed Posts: 11,803
    edited 2009-01-09 02:47
    @dnaddor
    The example is excellent. Very easy to read. Of course the object will be a singleton, but that is often useful anyway for device drivers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve
  • KyeKye Posts: 2,200
    edited 2009-01-09 18:41
    That is true dnaddor, but notice. You have to first acess all the variables and get them into the driver after its launched.

    You are using way more memory from all of that.

    Enjoy your new trick. =)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
Sign In or Register to comment.