Shop OBEX P1 Docs P2 Docs Learn Events
COGNEW ? — Parallax Forums

COGNEW ?

AGCBAGCB Posts: 327
edited 2014-12-06 13:37 in General Discussion
I notice in most assembly cognew instructions that +1 is added at end IE cognew(@entry,0)+1.
It was my reading of the manual that cognew starts in the next available cog. I did a debug of this and indeed it skips ahead by 2 when this +1 is pressent.

What is the reason for the +1?

Thanks
Aaron

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-12-05 12:40
    cognew returns a number from 0 to 7 on success, -1 on failure. Adding 1 changes this range to 0 (failure), 1 to 8 -- i.e. non-zero (success). It's just an easier result to test for success and to store for later a later cogstop. For the latter you have to subtract the 1 again.

    -Phil
  • AGCBAGCB Posts: 327
    edited 2014-12-05 12:45
    Thanks Phil
    So far in my programming I've just assumed they were going to start and not worried about testing (simple programs). I guess I have one more thing among thousands to learn.
    Aaron
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-12-05 13:13
    Phil explained this just fine but if you want to see it in the Propeller Manual, you can find it on page 120 of the version 1.0 manual.
    A Boolean result of FALSE is actually the
    numerical value 0 and TRUE is -1, but Boolean comparisons treat zero (0) as FALSE and any
    non-zero value (≠0) as TRUE. This is very convenient and is the reason we added 1 to
    COGNEW’s return value; the range -1 to 7 becomes 0 to 8, and 0 (FALSE) means no cog was
    started while 1 to 8 (TRUE) means a cog was started.

    Sounds like the same thing Phil said.

    I learned Spin from the v1.0 manual. Parallax later moved the Spin tutorial section out of the manual and into the Propeller Education Kit available in the Prop Tool's help menu.

    I still like the tutorial in the version 1.0 manual. I wasn't able to find the version 1.0 manual online so I've made it available from my Dropbox. Here's the link.
  • No Static At AllNo Static At All Posts: 9
    edited 2014-12-06 11:10
    Actually Parallax moved the Spin tutorial section out of the v1.0 manual
    and apparently hidden it in the Propeller Tool's help menu system.


    Hidden under the F1 function key.

    (Or select the first item in the Help menu - -> Propeller Help . . . F1.)


    Lot of good stuff there.


    "Spin Programming Tutorial" is the fourth item in the left column.

    Page 117 thru Page 123 (Exercise 7) in the v1.0 manual
    matches up with
    Lesson 6 in the Propeller Tool's "Spin Programming Tutorial".
  • AGCBAGCB Posts: 327
    edited 2014-12-06 13:37
    Thanks

    I was just studying in the prop manual and the PE tutorial. Even found I had previously highlighted some stuff.

    Aaron
Sign In or Register to comment.