Shop OBEX P1 Docs P2 Docs Learn Events
What if assembly code doesn't end with endless loop? — Parallax Forums

What if assembly code doesn't end with endless loop?

RaymanRayman Posts: 14,162
edited 2007-09-26 13:57 in Propeller 1
Ok, I'm sure this question has been asked and answered before, but the "Search" function here is about worthless!

Anyway, it appears that all the assembly code examples I've looked at end in an infinite loop.· What happens if there is no "jmp" at the end of the code?

Will it proceede to try to execute whatever is in the next address?· Or, does the compiler do some magic to make it stop there?

Comments

  • RaymanRayman Posts: 14,162
    edited 2007-09-25 18:07
    I've put this at the end to make it stop:

    'now stop
    COGID thisCog
    COGSTOP thisCog


    thisCog LONG 5

    Is there an easier way?
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-09-25 18:28
    COGID/COGSTOP is the safest way to end the execution of an assembly cog.

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

    Parallax, Inc.
  • RaymanRayman Posts: 14,162
    edited 2007-09-25 18:35
    Ok. Thanks. BTW, I find it strange that a Cog has to ask the Hub what it's own ID is!
  • cgraceycgracey Posts: 14,133
    edited 2007-09-25 18:41
    If you put nothing, it will execute whatever code was in main memory following your actual program, since a whole 496 longs were loaded from the starting point. Any assembly program should either loop or stop/restart its cog. Having no loop or cog stop/restart would be like driving your car for·a while and then ceasing to·steer it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-09-25 18:41
    All cogs are equal, each has an exactly identical structure, it is only how the hub treats them that makes them different.

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

    Parallax, Inc.
  • RaymanRayman Posts: 14,162
    edited 2007-09-25 19:18
    One more question, please. What happens if the 496th instruction is not a jmp? Does it roll over and start executing from the beginning? Or, does it start executing the "Special Purpose Registers"?
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-25 19:20
    Of course it executes the "special registers" - it only roles over at 512.
  • RaymanRayman Posts: 14,162
    edited 2007-09-25 19:38
    Just out of curiosity, can I set PAR (boot parameter) equal to "JMP #0" and thereby get it to start over after the 496th instruction?
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-09-25 19:46
    No because only 14 bits of PAR are settable.

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

    Parallax, Inc.
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-09-25 19:52
    Which means the CON field is 0000, therefore NOP? So waitcnt until it's = jmp #0. [noparse]:)[/noparse]
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-25 20:10
    All 32 bits of PAR can be set from within the COG.
    Paul describes a tricky behaviour of the COG loading, in that when cells $1F1 to $1FF are loaded the value is substituted by zero. When $1F0 is loaded its value is substituted by

    %%0000_0000_xxxx_xxx0

    Where %%YYYY_YYYY_xxxx_xxxY is the value stated in the second parameter of COGNEW
  • BaggersBaggers Posts: 3,019
    edited 2007-09-25 20:15
    yes, but if your going to waste, one or more instructions setting up PAR why don't you not bother and have the last instruction the jmp ?
  • RaymanRayman Posts: 14,162
    edited 2007-09-25 20:16
    Is $1F1 (system counter) actually set to 0? Guess it doesn't really matter since it would get updated before the cog starts executing...
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-25 20:43
    (a) Yes it will
    (b) No, it is not "updated"

    All "special registers" in a COG are "shadow registers" that will be read from "a different place", in case of INA, PHSA, CNT, PAR. There have been lengthy discussions wrt this behaviour...

    I fact I was unprecise before: ALSO $1F0 is set to 0 (the "shadow" register, i.e.). You will only get the "correct" PAR when reading through the source operand. When using the "dest" operand, PAR will be zero, also CNT!
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-09-25 21:08
    Just wondering, what happens when you restart a cog? Or restart a cog that isn't stopped? (Coginit bit 3 = 0)
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-25 21:24
    I think there is no "RESTART" - this is just a word used for STARTING a COG with a specific number...
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-09-25 23:15
    "The third field, bit 3, should be set (1) if a new cog should be started, or cleared (0) if a
    specific cog should be started or restarted." page 366

    Three questions then:
    1. Does the Cog get rewritten? (No, because otherwise it would be just a Cognew)
    2. Where does the Cog resume? At location 0, or the last operand+1?
    3. Does Par get reloaded?
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-25 23:37
    I still think there is no "RESTART" - this is just a word used for STARTING a COG with a specific number...
  • Mike GreenMike Green Posts: 23,101
    edited 2007-09-25 23:40
    1) The cog always gets rewritten
    2) The cog always starts at location zero
    3) PAR does get reloaded (from the 14 bit field passed to COGNEW/COGINIT)
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-09-26 02:02
    Thanks Mike.
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-26 06:06
    Fred lo longer believes my words :-(
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-09-26 12:52
    deSilva I never find you ambigious, just a bit curt. I, on the other hand, am often rude. Sorry.

    The manual in my opinion was ambiguous about 'restarting', which seems to me to have a different meaning than what was meant. Particularly when you have code already loaded. I was hoping to be able to stop a cog, and restart it without the overhead of the hub's filling up the cog's memory. In short, a jmp #0 under control of another cog.

    The manual might be clearer if it uses the terms 'launch' and 'relaunch' in the Coginit assembly write up:

    COGINIT
    [font=TimesNewRoman,Bold size=3]Instruction: [/font]Start or restart·Launch or relaunch a cog, optionally by ID, to run Propeller Assembly or Spin code.
    COGINIT Destination
    [font=TimesNewRoman,Bold size=3]Result:
    [/font]Optionally, the started/restarted launched/relaunched cog’s ID (0-7) is written to [font=TimesNewRoman,Italic size=3]Destination[/font].

    Post Edited (Fred Hawkins) : 9/26/2007 12:58:04 PM GMT
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-26 13:36
    Fred, for what reasons ever, the Propeller world is full of misnomers. Take the somewhat forced object oriented lingo, calling the maximum-function "min" and the minimum function "max", or a simple sequence of memory cells an "array" smile.gif
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-09-26 13:57
    Could be worse, like "dextral transpressure".
Sign In or Register to comment.