Shop OBEX P1 Docs P2 Docs Learn Events
Step Debug (newbie to BS2) — Parallax Forums

Step Debug (newbie to BS2)

ArchiverArchiver Posts: 46,084
edited 2000-09-28 17:05 in General Discussion
Is there a way to step through source code in debug mode. Also, is
the IF -Then statement a true branch or should the code return if it
goes to a subroutine. The manual seems to indicate that there is no
return unless the GOsub was used. Thanks

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-09-28 17:05
    You can't exactly step, but you can pepper your code with DEBUG statements
    to see what's happening.

    The IF is just a branch. If you want to call a subroutine, you'll have to
    put a gosub as the target of the IF and then jump back to where you want:

    WRONG:

    if x=10 then foo
    gosub do_something_else

    foo:
    high 4
    return

    RIGHT:


    if x=10 then call_foo
    foo_ret:
    gosub do_something_else

    .
    .
    .

    call_foo:
    gosub foo
    goto foo_ret

    foo:
    high 4
    return


    Of course, this assumes you are calling foo from somewhere else too, or else
    you might just as well write:

    if x=10 then foo
    foo_ret:
    gosub do_something_else
    .
    .
    .
    foo:
    high 4
    goto foo_ret


    Another nice trick is to put a label (maybe RET) in front of any return
    statement you happen to have in your program:


    foo:
    high 4
    RET:
    return


    Then inside a subroutine you can write:

    if x=100 then RET

    to return conditionally from the subroutine.


    Regards,

    Al Williams
    AWC
    * Control 8 servos at once! http://www.al-williams.com/awce/pak8.htm



    >
    Original Message
    > From: rheine@m... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=yVcG9Ue6-IkKIg2JIQKXhHPEVCh3xsLWNiqcWpTGQUAu70n6D_k3reHKpq7eVIpMLsTg0BezJXR2KEc]rheine@m...[/url
    > Sent: Thursday, September 28, 2000 10:11 AM
    > To: basicstamps@egroups.com
    > Subject: [noparse][[/noparse]basicstamps] Step Debug (newbie to BS2)
    >
    >
    > Is there a way to step through source code in debug mode. Also, is
    > the IF -Then statement a true branch or should the code return if it
    > goes to a subroutine. The manual seems to indicate that there is no
    > return unless the GOsub was used. Thanks
    >
    >
    >
Sign In or Register to comment.