Shop OBEX P1 Docs P2 Docs Learn Events
Is there a formal description for setting up/handling variables between Spin an — Parallax Forums

Is there a formal description for setting up/handling variables between Spin an

HarleyHarley Posts: 997
edited 2008-04-20 23:24 in Propeller 1
I tried a search for this subject, but what came up wasn't too helpful. Maybe didn't use the proper words.

And I don't want to reverse engineer some program to hopefully derive how to do this correctly.

I have two Props, and on one I have had something which seems to work. But attempting to do so on other Prop, I cannot figure out how to do so again. All I need is to pass several variables (1/2 dozen) from Spin to Asm, and do so also from Asm to Spin. Seems it should be easy, but have spent too many hours/iterations and yet it doesn't work.

Only have to do so with two cogs. But one cog also needs to affect (change) a variable between cogs. Need something explained simply to get my head around this detail.
Thanks for any/all help. yeah.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-18 23:02
    Harley,
    Do make sure you've looked at the assembly tips and traps and DeSilva's tutorial on Propeller assembly coding in the "sticky" threads at the top of the forum subject list.

    The easiest way to reference some Spin variables from assembly is to group them together and make them all longs, then pass the address of the first one as the 2nd parameter to COGNEW when you start the assembly routine like:

    COGNEW(@entryPoint,@firstVar)

    In the assembly routine, you access the first long with: RDLONG anywhere,PAR or WRLONG anywhere,PAR.
    For the other variables, you'll need to move PAR to another location and increment it as in:

    MOV temp,PAR
    ADD temp,#4
    RDLONG anywhere,temp

    and do similar things to access the other variables.
    Obviously, if you want to access WORDs or BYTEs, you'd use RDWORD or RDBYTE and increment the address appropriately.
    Remember, the Spin compiler sorts the variables in size order (LONGs first, then WORDs, then BYTEs). They're not placed
    in the order of declaration unless they're in a DAT section.

    Post Edited (Mike Green) : 4/18/2008 11:07:39 PM GMT
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-04-18 23:18
    You can also do something like this
    VAR
      long aVariable
    PUB start
      address=@aVariable         'save the address of aVariable into a variable that will be loaded into the cog
      aVariable=5                     'make the variable something
      cognew(@entryPoint,0)     'start the cog
      
    DAT
      org 0
    entyrPoint 
    rdlong temp,address           'read aVariable into the cog   
    add temp,#5                      'do something to it
    wrlong temp,address           'write it back to the hub
    
    temp long 0                        'somewhere for temporary usage
    address long 0                    'a place to hold the address of aVariable
    
  • HarleyHarley Posts: 997
    edited 2008-04-18 23:54
    Thanks Mike and Steven,

    Mike, thanks for that clear explanation. I think I've done what you describe; maybe there is something else I'm doing wrong. Got to take time to review just what is going on presently.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Harley Shanko
  • HarleyHarley Posts: 997
    edited 2008-04-20 23:24
    Mike,

    Again thank you for the guidance. I found that I had a '@' symbol in an inappropriate location; compiled OK, and therefore was not doing what was intended.

    I do have a hard copy of Phil's Tips and Traps and DeSilva's tutorial; very helpful, though possibly not up to date. But doesn't help when a stupid typo is in place.

    Things working better now. Lots more debugging yet though.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Harley Shanko
Sign In or Register to comment.