Shop OBEX P1 Docs P2 Docs Learn Events
best way to access variable of an object — Parallax Forums

best way to access variable of an object

Scott LewisScott Lewis Posts: 18
edited 2009-02-19 01:27 in Propeller 1
I don't know weather to use a get method or pass addresses to access variables modified by some assembly code, so far I can't get the address passing via the start method to work. below is an example of what I mean:

VAR
   long data(5]

PUB start(dataAddr0,dataAddr1,dataAddr2,dataAddr3,dataAddr4)
   longmove(@data[noparse][[/noparse]0],@dataAddr0,5)
   cognew(@entry,@data[noparse][[/noparse]0])

DAT

org 0
entry
'assembly code here which modifies data[noparse][[/noparse]] elements




I thought the call to this start method which passed pointers to its own data variables would then be able to access the latest values without a get(index) method, but it doesn't work for some reason.

Comments

  • KyeKye Posts: 2,200
    edited 2009-02-19 00:26
    Notice what happens when data is passed with the par register and you will understand what the problem is. That being that the address is slightly truncated unless its pushed up some.

    And, these a very easy way arround this.

    Since asm code just floats arround in the main memory it can be acessed like any other code.

    So, you can assign and asm long variable the address of a variable for spin and then launch the processor with all the addresses embeded in it.

    Like:

    var
    stuff [noparse][[/noparse]6]

    Pub

    adrStuff := @stuff
    cognew...

    Dat
    ...
    adrStuff long 0

    ......

    Doing it this way is quick and painless.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Mike GreenMike Green Posts: 23,101
    edited 2009-02-19 00:33
    You didn't say what you're trying to do with the start method with all the different parameters. If you just have a 5 long work area that you're trying to pass to the assembly, you only need the address of the first long. In other words:
    ' call with myObject.start(@myArray)
    PUB start(addressOfLongs)
       cognew(@entry,addressOfLongs)
    DAT
    entry  rdlong temp1,par  ' 1st parameter
             mov    tempAddr,par
             add     tempAddr,#4 ' 2nd parameter
             rdlong temp1,tempAddr
    


    If you want to pass several parameter addresses, you could do
    PUB start(dataAddr0, dataAddr1)
       pointer0 := dataAddr0   ' Set pointers in hub memory
       pointer1 := dataAddr1
       cognew(@entry,0)   ' Copy code and initialized pointers to cog & start
    DAT
    entry  rdlong   temp1,pointer0
             rdlong   temp2,pointer1
    
    pointer0 long  0   ' Set by start routine before
    pointer1 long  0   '  code is copied to the cog
    
  • Scott LewisScott Lewis Posts: 18
    edited 2009-02-19 01:01
    the problem isn't passing longs to the asm code with the par register, it is a simpler problem of passing it to parent object. I have got my asm code to work and to print out with PST within the same object. the problem is when another object declares an instance of the first object how to get the data out in pointer form. so both objects working together how i want to do it would look like this:

    first object, declared by 2nd object:
    'object1.spin
    
    VAR
    
    long data{5]
    
    PUB start(dataAddr0,dataAddr1,dataAddr2,dataAddr3,dataAddr4)
    
    longmove(@data[noparse][[/noparse]0],@dataAddr0,5)
    cognew(@entry,@data[noparse][[/noparse]0])
    
    DAT
    org 0
    entry
    'asm code which modifies data[noparse][[/noparse]]
    
    



    2nd object, declares first object
    'object2.spin
    
    OBJ
      object : "object1"
      debug : "FullDuplexSerial"
    
    VAR
      long data{5]
    
    PUB go | index
    
      object.start(@data[noparse][[/noparse]0],@data{1],@data{2],@data{3],@data{4])
      debug.start(31,30,0,9600)
    
      repeat
        debug.tx(16)
        repeat index from 0 to 4
          debug.str(string("data "))
          debug.dec(index)
          debug.str(string(": ")
          debug.dec(data[noparse][[/noparse]index])
          debug.tx(13)
        waitcnt(cnt + clkfreq/10)  
    
    



    now in theory, the 2nd object should print out whatever the first object stores in its data variables, but it doesnt. I have verified that it is able to store the variables in main memory and the asm code works by putting the loop to print them out in object1 and removing the parameters to the start() method and loading the code directly. I do not want to use a get(index) method to return the data each time because it needs to be semi-fast.

    Post Edited (Scott Lewis) : 2/19/2009 1:08:01 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2009-02-19 01:14
    What you need is for the start routine to be given the address of a 5 long area in the main program's object. The start routine passes this address to the assembly routine using PAR (and the assembly routine accesses it through PAR). The main program can then reference the longs directly and can pass the address of this area to other objects that may need to manipulate it. You'd use my first example with a main program like:
    obj  object : "object1"
          debug : "FullDuplexSerial"
    var long data[noparse][[/noparse] 5 ]
    PUB go | index
    object.start(@data)
    debug.start(31,30,0,9600)
    repeat
       repeat index from 0 to 4
          debug.dec(data[noparse][[/noparse]index])
          debug.tx(13)
    
  • Scott LewisScott Lewis Posts: 18
    edited 2009-02-19 01:27
    works, thx
Sign In or Register to comment.