Shop OBEX P1 Docs P2 Docs Learn Events
Access from Spin to assembly arrays — Parallax Forums

Access from Spin to assembly arrays

IBIB Posts: 3
edited 2007-03-24 09:22 in Propeller 1
Hi people,
I'm implementing a signal filtering application using the Propeller chip.
I have taken audio samples using assembly and I have stored them into an array also defined in the DAT section.
I want to write my application using Spin language, so I need to access the sampled data (assembly) from the Spin code.

Does anyboby know how I can do it or where I can find an example?

Thank you,
IB

Comments

  • bambinobambino Posts: 789
    edited 2007-03-23 13:29
    I've not tried arrays in assemble, but access to assembly variables is pretty straight forward.
    var
    long spinvar
     
    pub main
     spinvar:=assmVar
     
     
     
    dat
    assmVar long $55555555
    

    The above won't work if the assembly is in another cog though. You would be dealing with offsets then!

    PS. Check out the Tricks & traps Thread.

    Hope this Helps!

    Post Edited (bambino) : 3/23/2007 1:37:41 PM GMT
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-03-23 18:23
    Bambino,

    Are you sure that's right, you can't have spin and assembly in the same cog, in the same object yes but not the same cog that was my understanding.

    You can write to the cog's local assembly variable before starting the cog to load it with data on start up and you can have spin routines for the object that get the data from global memory that has been moved using wrlong commands but I don't think you can get data directly from assembly to spin like that.

    Graham
  • Jasper_MJasper_M Posts: 222
    edited 2007-03-23 18:30
    Are you using wrlong, wrword or wrbyte in ASM? You should be, because like Graham Stabler said, Cog and SPIN can't run on the same cog and if you're accessing the buffer in DAT section with "mov"s or something like that, the changes happen in Cog's own memory - not in shared memory. You have to pass the pointer to the buffer with PAR register, using the last argument of cognew or coginit. (Value of the argument appears in the read-only PAR register in ASM) Then you write to that buffer using wrlong,wrword or wrbyte. In spin you can read it with BYTE[noparse][[/noparse]@myArray + index] or WORD or whatever. Keep also in mind that the array in DAT block will not be aligned - it'll be a problem if it is words or longs. Also, if you have multiple instances of the object, you still have only one array.
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-03-23 18:35
    So basically I think that when you start your assembly cog you need to pass it a pointer to an array in hub memory (defined in Var section). Then when you have collected your data you use a loop and the wrlong command to move the data from the cog memory (in your dat section with the assembly) to the hub memory (defined in the var section). You can see the concept put into practise in the mouse and keyboard routines but for single variables, when its an array and say its of longs you just add 4 to the address to get to the next long (4 bytes make a long).

    Graham
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-23 18:41
    Unless you're already using the WRxxxx instructions, you're not actually storing your samples in the DAT section. The DAT section is copied to a cog's local memory when the COGNEW or COGINIT is executed and the instructions actually refer to locations within the cog's memory. The only way to get data in or out to main memory is with the RDxxxx/WRxxxx instructions as others have described earlier. Start by looking at their descriptions in the manual and in the Assembly Code Examples for the Beginner "sticky thread" in this forum.
  • TransistorToasterTransistorToaster Posts: 149
    edited 2007-03-23 18:47
    I've been though most of these problems this week. Take a look at all the threads started by me, you'll find useful stuff. In a nutshell, to pass the address of an array from spin to ASM do this:
    VAR
    array

    PUB
    cognew(@asmstart, @array)

    DAT
    mov pointer, par '(par=parameter value= address of first location of array)
  • IBIB Posts: 3
    edited 2007-03-24 09:22
    Thank you all!

    I thought to the memory this morning. I think I will use wrxxx command to write my samples (and really store them) in the memory and then I will recall from there.
    Moreover it is better to take a look to the resources you gave me.

    Thank you again [noparse]:)[/noparse]
    Ivano.
Sign In or Register to comment.