Shop OBEX P1 Docs P2 Docs Learn Events
How would this assembly compile? — Parallax Forums

How would this assembly compile?

SteelSteel Posts: 313
edited 2007-08-29 18:21 in Propeller 1
So I am looking at this code:
___________________________________________________
PUB DO_THINGS
···
·· COGINIT(1,@DO_THING_1,0)
·· COGINIT(2,@DO_THING_2,0)
·· COGINIT(3,@DO_THING_3,0)


DAT
·· ORG·· 0
DO_THING_1
·· {THIS CODE WILL CONTINUALLY LOOP}
·· JMP· #DO_THING_1

DO_THING_2
·· {THIS CODE WILL CONTINUALLY LOOP}
·· JMP· #DO_THING_2

DO_THING_3
·· {THIS CODE WILL CONTINUALLY LOOP}
·· JMP· #DO_THING_3

THING_1_CON_1··· Long·· $0
THING_1_CON_2··· Long·· $0
THING_2_CON_1··· Long·· $0
THING_2_CON_2··· Long·· $0
THING_3_CON_1··· Long·· $0
THING_3_CON_2··· Long·· $0
_______________________________________________________

When this code is compiled, does the entire DAT get copied to every cog...or does just the section that is called by the "COGINIT" Command get copied to the cog?

When this code is compiled, do all of the declared constants get compiled onto every cog, or just the cog that runs the ASM that calls them?
·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-28 16:06
    The COGINIT/COGNEW copies 512 longs (2K bytes) from HUB memory to the cog's memory regardless of what's there, then starts the cog at location zero. That's it. Whatever follows the DO_THING_n in memory gets copied. Obviously, anything beyond the end of your cog program is not particularly important to the program running in the cog. If there's no more DAT information, then whatever follows the DAT section in HUB memory is copied.
  • potatoheadpotatohead Posts: 10,260
    edited 2007-08-28 16:34
    Does this mean short programs get each others code loaded into the COGs?

    Say, I've three programs that all are 50 longs each. If they are in the DAT, back to back, will all of them end up in the first COG?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-28 16:41
    I thought I explained that in my tutorial... O.k. I'll try better next time...

    The answer is: YES and NO smile.gif
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-28 16:42
    Just believe what Mike explained above...
  • hippyhippy Posts: 1,981
    edited 2007-08-28 16:43
    @ potatohead : Yes.

    In the OP's example - Cog 1 is loaded with Cog 1 code, followed by Cog 2 code, followed by Cog 3 code, followed by <whatever> - Cog 2 is loaded with Cog 2 code, followed by Cog 3 code, followed by <whatever> - Cog 3 is loaded with Cog 3 code followed by <whatever>.

    Although ... shouldn't there be an "ORG 0" before each DO_THING_x ?

    Post Edited (hippy) : 8/28/2007 4:48:29 PM GMT
  • potatoheadpotatohead Posts: 10,260
    edited 2007-08-28 17:29
    deSilva,

    I've simply not read that part, and asked the question out of topical interest. There are some specific things I need to work through and this isn't one of them at the moment. Don't take that as failure or lack of clarity on your excellent tutorial. It isn't.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-28 17:51
    hippy said...
    Although ... shouldn't there be an "ORG 0" before each DO_THING_x ?
    By all means!
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-08-28 22:46
    Mike, I thought the last 16 longs are reserved. Why wouldn't it be a 496 long copy from hub to ram?
  • ericballericball Posts: 774
    edited 2007-08-29 17:13
    Steel said...

    When this code is compiled, does the entire DAT get copied to every cog...or does just the section that is called by the "COGINIT" Command get copied to the cog?

    When this code is compiled, do all of the declared constants get compiled onto every cog, or just the cog that runs the ASM that calls them?
    As has been stated, COGINIT copies 496 longs starting at the address provided.· Therefore, you need to have an ORG 0 before each address so any labels get translated correctly.

    PUB DO_THINGS
        
       COGINIT(1,@DO_THING_1,0)
       COGINIT(2,@DO_THING_2,0)
       COGINIT(3,@DO_THING_3,0)
     
     
    DAT
       ORG   0
    DO_THING_1
       {THIS CODE WILL CONTINUALLY LOOP}
       JMP  #DO_THING_1
    THING_1_CON_1    Long   $0
    THING_1_CON_2    Long   $0
     
       ORG   0
    DO_THING_2
       {THIS CODE WILL CONTINUALLY LOOP}
       JMP  #DO_THING_2
    THING_2_CON_1    Long   $0
    THING_2_CON_2    Long   $0
     
       ORG   0
    DO_THING_3
       {THIS CODE WILL CONTINUALLY LOOP}
       JMP  #DO_THING_3
    THING_3_CON_1    Long   $0
    THING_3_CON_2    Long   $0
    
    

    Warning! This means THING_3_CON_1 is translated relative to DO_THING_3.· The code in DO_THING_1 will not be able to access anything after the ORG 0 without some additional trickery even if it's within 496 longs of DO_THING_1.· (Not to mention that each cog is working on a local copy, so updates aren't reflected across cogs.)
    ·
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-29 17:21
    Actually, I believe 512 longs get copied. The last 16 longs go into "shadow registers" since these are "overlaid" with functional registers. Some of these shadow registers are still partially accessible by using them in the destination field of an instruction (like CNT and INA for example), but that's a longer discussion.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-08-29 17:31
    512 locations are read, however for the last 16 locations what is read is ignored and a forced write of 0 is performed (with the exception of the PAR register).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-29 18:21
    So it takes 512*16 ticks until the new COG can start its work; I think the tricky last part is done to save some extra logic to clear the shadow registers. And PAR must be somewhat tricky!
Sign In or Register to comment.