Shop OBEX P1 Docs P2 Docs Learn Events
Is it possible/practical to run sections of a single DAT section in separate cogs? — Parallax Forums

Is it possible/practical to run sections of a single DAT section in separate cogs?

OctahedronOctahedron Posts: 18
edited 2011-05-09 08:18 in Propeller 1
What I am trying to do is to pass a memory location of common HUB memory pool to two separate cogs and simply make sure it is an even number and past the value to the very next long and see if it works. If I use separate objects and call each object and it loads the PASM into each cog it works. If I try to put them together and point further down in the DAT section and start from there it doesn’t work. Am I trying to do something that is not possible?

Thanks for your time.
PUB Start(MemoryPointer) 

  cognew(@entry, MemoryPointer)
  cognew(@even, MemoryPointer)
   
DAT

'* Assembly language memory writing *

'KISS - read it, write it, correct odd numbers.
'@entry all the PASM is loaded but zero loop never runs
'@even the entry loop should not be loaded into the second cog 
'but seem to be anyway so it is broken! 

            org     0

entry       mov     t1,par    'get starting address of the memory pool
            rdlong  t2,t1     'get the first value
            add     t1,#4     'skip to the next long 4 bytes away
            wrlong  t2,t1     'write the the value from the first memory location to the second
            jmp     entry     'Well that was so much fun lets do it again!


'The other part I wish to run to make the first number only even and runs in its own cog!

even         mov     t1,par                  'get starting address of the memory pool
             rdlong  t2,t1                    'get the first value
             test    t2, #1   wz             'Is it even?
      if_nz  add     t2,#1                    'If it is odd add one to it
      if_nz  wrlong  t2,t1                    'Correct the odd number
             jmp     even                     'Lots of fun, lets do it again!



' Uninitialized data
'
t1        res     1
t2        res     1

          fit     496

Comments

  • davidsaundersdavidsaunders Posts: 1,559
    edited 2011-05-08 10:44
    This is easy just remember to tell the Prop tool that the code starts at 0 relative to the cog, by giving it an org 0.

    hough in your 'even' routine you are only reading and writing the first value in the pool, is this intentional?

    Thinking probably not, remember that each cog gets a separate copy of the variables that get loaded into COG mem.

    Here is the modification, I would also duplicate the cog variables if I were you.
    PUB Start(MemoryPointer) 
    
      cognew(@entry, MemoryPointer)
      cognew(@even, MemoryPointer)
       
    DAT
    
    '* Assembly language memory writing *
    
    'KISS - read it, write it, correct odd numbers.
    '@entry all the PASM is loaded but zero loop never runs
    '@even the entry loop should not be loaded into the second cog 
    'but seem to be anyway so it is broken! 
    
                   org     0
    
    entry       mov     _t1,par    'get starting address of the memory pool
                   rdlong  _t2,_t1     'get the first value
                   add     _t1,#4     'skip to the next long 4 bytes away
                   wrlong  _t2,_t1     'write the the value from the first memory location to the second
                   jmp     entry     'Well that was so much fun lets do it again!
    
    ' Uninitialized data
    'you Must put a seperate set of variables here.
    _t1        res     1
    _t2        res     1
    
    'The other part I wish to run to make the first number only even and runs in its own cog!
                     org 0
    even         mov     t1,par                  'get starting address of the memory pool
                     rdlong  t2,t1                    'get the first value
                     test     t2, #1   wz             'Is it even?
           if_nz  add      t2,#1                    'If it is odd add one to it
           if_nz  wrlong  t2,t1                    'Correct the odd number
                    add       t1,#4
                    jmp       even                     'Lots of fun, lets do it again!
    
    
    
    ' Uninitialized data
    '
    t1        res     1
    t2        res     1
    
              fit     496
    
  • davidsaundersdavidsaunders Posts: 1,559
    edited 2011-05-08 11:12
    I found my error above, see edited version of my previous post.
  • OctahedronOctahedron Posts: 18
    edited 2011-05-08 11:16
    If I understand what is going on: The closest org 0 to the cognew entry point in the DAT section is used by the compiler to set the code into the start of cog memory and my code the org 0 told the complier to load all of the DAT section. Is that correct? By the way it works like a charm!

    As for my intentions with this code, yes the simple functions are intentional. One cog to is only used to move the number from the first to the second and the other ensures that the number in the first memory location is even. I was trying to understand the problem so I kept it as simple as possible.

    Thanks for your time and help!
  • davidsaundersdavidsaunders Posts: 1,559
    edited 2011-05-08 11:19
    No not quite. And you are quite welcome.

    The cognew(@even,MemoryPointer) loads the code starting at the address of even into the cog beginning at address 0, though with out the second ORG 0 your assembly is compiled as if it starts at a higher address so when your loop happens it is jumping to an address past the end of the code (because the label offset was calculated for a different base address than is being used).
  • kuronekokuroneko Posts: 3,623
    edited 2011-05-08 18:34
    DAT
                org     0
    
    entry       mov     t1,[COLOR="blue"]par[/COLOR]    'get starting address of the memory pool
                rdlong  t2,t1     'get the first value
                add     t1,#4     'skip to the next long 4 bytes away
                wrlong  t2,t1     'write the the value from the first memory location to the second
                jmp     [COLOR="red"]#[/COLOR]entry    'Well that was so much fun lets do it again!
    
    
    'The other part I wish to run to make the first number only even and runs in its own cog!
    
                org     0
    
    even        mov     t1,[COLOR="blue"]par[/COLOR]                 'get starting address of the memory pool
                rdlong  t2,t1                  'get the first value
                test    t2, #1   wz            'Is it even?
          if_nz add     t2,#1                  'If it is odd add one to it
          if_nz wrlong  t2,t1                  'Correct the odd number
                jmp     [COLOR="red"]#[/COLOR]even                  'Lots of fun, lets do it again!
    
    Right now (without #) you're lucky that the jump picks up $1F0 (par) as its target. This means all the SPIN code in the cog is skipped and it basically wraps around ($1F0..$1FE, $1FF: nop) and starts execution at location #0 again.
  • davidsaundersdavidsaunders Posts: 1,559
    edited 2011-05-09 08:18
    Kuroneko:
    Thank you, I feel bad that I did not notice that, I hope you got in in time to prevent him making a habit of that.
Sign In or Register to comment.