Shop OBEX P1 Docs P2 Docs Learn Events
trying to understand Longmove — Parallax Forums

trying to understand Longmove

Blake KochBlake Koch Posts: 39
edited 2020-10-08 17:00 in Propeller 1
If I'm writing a program that has two objects running in two separate cogs. The first cog has Global VAR long a,b,c declared, I then want Longmove(@a,@ABC,3) to cog two.
here is my question.

How do I move @ABC back into Var a,b,c in cog two so I could then use these variable for something else.

thanks
Blake

Comments

  • The longmove instruction works with hub RAM, so I'm assuming you want to exchange values between the global variables in each cog. To do this, you need to know source and destination addresses. In my objects I frequently have a method called address() that reviews the address of a variable/array that I may want to allow direct access to from outside. For example, in my DMX receiver, I have this method.
    pub address()
    
    '' Returns hub address of dmx buffer
    '' -- allow direct access to buffer by parent object
    
      return @dmxbuf
    
    This lets me use dmx.address as the source address parameter in a xxxxmove instruction.

    You may need to add similar methods to each object so that the parent object can move data directly between the two.
  • So if I understand this. in the sending Object, I create a method that copies @a to @ABC,
    Sending Object (cog 2)

    object 1
    VAR
    LONG a,b,c,
    PUB Something(ABC)
    longmove(ABC,@a,3)

    In the Receiving Object ( cog 1) I just have to Call Object1, the method and the address of the global variable.
    object2
    PUB Something_else | a,b,c
    object1.Something(@ABC)
    a + b + c := d

    Then I could use (d = a+b+c) or some other manipulation of a,b or c.
  • JonnyMacJonnyMac Posts: 9,159
    edited 2020-10-08 19:31
    It would be easier to see your actual objects. Something that you have to consider is that child objects cannot call methods from each other. Let's say ObjectA ( a child of the main app) holds some values that ObjectB (also a child of the main app) wants to manipulate and put back.

    In ObjectA, put the variables you want to share together an in order; let's say they are called first, second, and third.
    var
    
      long  first
      long  second
      long  third
    
    Create a method called shared in ObjectA.
    pub shared
    
      return @first
    
    The next step is to create a method in ObjectB (which does the work on the variables originating in ObjectA) that gets the shared address of ObjectA via the main app.
    pub get_shared(addr)
    
      shared := addr
    
    The main application does this:
      ObjectB.get_shared(ObjectA.shared)
    
    Now ObjectB knows where the ObjectA values are stored and can manipulate them. ObjectB can make local copies of the ObjectA variables like this:
      longmove(@firstcopy, shared, 3)
    
    Remember, shared is an address so you don't need to use @ with it in this case. ObjectB can put values back by reversing the source and destination terms.
      longmove(shared, @firstcopy, 3)
    
    Variable names are pleasant ways to deal with variable addresses. Once you know where the variables are located in RAM, you can directly affect them. For example, if ObjectB wanted to add ObjectA's first and second variables and store the result in the third, you could do this.
      long[shared+8] := long[shared] + long[shared+4]
    
    It's not pretty, but it works.
Sign In or Register to comment.