Shop OBEX P1 Docs P2 Docs Learn Events
Memory locations in Spin — Parallax Forums

Memory locations in Spin

tom90tom90 Posts: 55
edited 2008-02-14 01:20 in Propeller 1
Hey All,

I have a cog running ASM that writes a word/long to a specific memory location
For example:
wrword    AdcValue, $1FF

I would like to have another cog running spin that will read this word/long from that specific location so it can be output.
How do I read from a specific memory location in spin?

The manual addressed something similar but it didn't really explain this situation.

Thanks,
Tom

Comments

  • deSilvadeSilva Posts: 2,967
    edited 2008-02-13 19:41
    It' just
    X := WORD[noparse][[/noparse]$1ff]
    


    But you should not write to $1ff in the first place...
  • tom90tom90 Posts: 55
    edited 2008-02-13 19:45
    deSilva,

    I have tried this, and it comes up with an error message that says "Expected a Variable"
    CON
      _clkmode = xtal1 + pll4x                          
      _xinfreq = 5_000_000
      try = 500
    

    OBJ
    ··· debug : "pc_debug"
    VAR
    · long· answer
    ·
    PUB Main
    · debug.start(2_400)····
    · cognew(@divtest, 0)
    ·
    ·· answer := 0
    repeat
    · answer := word[noparse][[/noparse]@$1FF]
    · debug.str(string("Answer "))··········
    · debug.dec(answer)
    · debug.str(string("· "))

    DAT
    ············· ORG······ 0
    divtest······
    ·············
    :loop········ mov······ Total, A1
    ············· add······ Total, A2
    ············· add······ Total, A3
    ············· add······ Total, A4
    ············· add······ Total, A5
    ············· add······ Total, A6
    ············· add······ Total, A7
    ········································
    ············· wrword··· Total, $1FF
    ············· jmp······ #:loop
    A1····· long··········· 1
    A2····· long··········· 2
    A3····· long··········· 3
    A4····· long··········· 4
    A5····· long··········· 5
    A6····· long··········· 6
    A7····· long··········· 7
    Total·················· res 1·
    
    
    What am I doing wrong?

    Thanks

    Tom
  • deSilvadeSilva Posts: 2,967
    edited 2008-02-13 19:52
    What should the "@" be for????
  • tom90tom90 Posts: 55
    edited 2008-02-13 20:12
    Thanks deSilva, that was pretty dumb of me.

    Now I am getting a very high incorrect value.

    I am assuming that my variables arent defined correctly.· I just tried several configurations but didnt have any luck

    Any ideas?



    Thanks,

    Tom
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-02-13 20:23
    If you must write to location $1ff, the correct way to do it is with an immediate operand:

            wrword   AdcValue, [b]#[/b]$1ff
    
    
    


    The code you were using was writing to the address contained in register $1ff. In any event, why are writing to that location when you have no idea what you might be clobbering in the process?

    -Phil
  • tom90tom90 Posts: 55
    edited 2008-02-13 20:41
    Phil

    First of all, thanks.

    The answer to your second question is because i am a terrible programmer.· I was doing this because I needed to pass multiple things between cogs, and didnt know how else to do that.· Where should I be writing these varaibles so that i dont disturd anything important.·

    Thank

    Tom
  • hippyhippy Posts: 1,981
    edited 2008-02-13 20:54
    The best place to write to memory is at the top of the RAM address range, ( $7FFF ) downwards. If you were writing a long, that would be $7FFC.

    This is assuming that nothing has taken that memory for its own use; video buffer, etc.
  • tom90tom90 Posts: 55
    edited 2008-02-13 21:01
    hippy,

    When i try to write to anything higher than $1FF it comes back with an error message that says "Source register/constant cannot exceed $1FF".· How do i write to a location higher than $1FF?

    thanks

    Tom


    Post Edited (tom90) : 2/13/2008 9:11:59 PM GMT
  • Nick MuellerNick Mueller Posts: 815
    edited 2008-02-13 21:12
    > When i try to write to anything higher than $1FF it comes back with an error message that says "Source register/constant
    > cannot exceed $1FF"

    As deSilva already said, it's no good idea to write to $1FF. It's also not good to write to $whateverValue.
    You need to define a var in SPIN and pass that address to your assembler routine. Here, you can access the parameter (the address in this case) via PAR.

    If you insist on using some constant address that you have chosen, you insist on having unpredictable results.


    Nick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Never use force, just go for a bigger hammer!

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-13 21:12
    That would be because you can only store up to nine bytes in an instruction. A better way to do it is
    VAR word someVariable 'the variable that you want to be able to access  from spin and assembler
    
    PUB
      'other code
      cognew(@divTest,@someVariable)
      'other code
    
    DAT
                  ORG       0
    divtest       
                  
    :loop         mov       Total, A1
                  add       Total, A2
                  add       Total, A3
                  add       Total, A4
                  add       Total, A5
                  add       Total, A6
                  add       Total, A7
                                             
                  wrword    Total, PAR
                  jmp       #:loop
    A1      long            1
    A2      long            2
    A3      long            3
    A4      long            4
    A5      long            5
    A6      long            6
    A7      long            7 
    Total                   res 1
    



    This way you don't have to worry about whether the memory is being used by something else.
  • tom90tom90 Posts: 55
    edited 2008-02-13 21:25
    Thanks Guys

    The code i posted was just a small test program that i wrote to make sure that passing the variables was working.· In the larger program that i have written (and this test will be a part of) uses the "PAR" to sync all of the cogs together.· Is there a way to use more than one "PAR" on each cog?· I was trying to write to these other memory location because i didn't know how to pass aroung variable once i already had that "par" assigned to something else.

    Thanks
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-13 21:30
    You can only store one long in a PAR. However you can fit two addresses into a long because they are only words. The other option is to pass in an address where pointers to all you data is.
  • deSilvadeSilva Posts: 2,967
    edited 2008-02-14 01:13
    There is a third option (also discussed in my "Tutorial" smile.gif ):

    You can set addresses (or other values) to DAT variables to be copied in the COG - of cause BEFORE you have it copied by COGNEW smile.gif
    
    parA := @result1
    parB := @result2
    parC := 4711
    COGNEW(@asm,0)
    
    DAT
        ORG 0
    asm
    ' put your code here
    
    
    parA LONG 0
    parB LONG 0
    parc LONG 0
    
    


    I am aware that there are reasons to NOT do it that way, but it also has its merrits smile.gif

    @Steven:
    cognew(@divTest, @someVariable)
    


    is also NOT a good idea as someVariable is a WORD. The problem is that PAR is not a LONG, but a quite specific 14-bits value, allowing addresses of LONGs only!!! It works by chance in your example , as someVariable is the FIRST WORD and is thus aligned to LONG...

    Post Edited (deSilva) : 2/14/2008 1:20:02 AM GMT
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-14 01:20
    True, should make someVariable a long and then it won't be a problem smile.gif
Sign In or Register to comment.