variables and gosubs???


Closed Thread
Results 1 to 39 of 39

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    I'll try something...

    Code:
    StartPoint:
        Gosub Somewhere
    Label1:
        Pause 100
        Goto Start
    Somewhere:
        Pause 1
        Return
    Nothing hard here right? after the Return... you return to Label1 ... right?

    Now...
    Code:
    StartPoint:
        Gosub Somewhere
    Label1:
        Pause 100
        Goto Start
    Somewhere:
        Goto SomewhereElse
        z: goto z    
    
    SomewhereElse:
        Return
    Same thing happen here...

    This said...

    Code:
    Start:                         
          for routines=0 to 3
    StartPoint:
              gosub subselect
    ReturnPoint:
              pause 200
              next
        goto start
    
    SubSelect:
              branchl routines, [Routine0, Routine1, Routine2, Routine3]    
              
    Routine0:
             return
    Where the Return of Routine0 leads you?... to ReturnPoint

    I know i'm a pretty bad teacher...
    Last edited by mister_e; - 18th November 2006 at 20:02.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    and I am a good student.


    I thought that once the program jumps, then it will forget where it was and will return to an unknown place. So that it will never be 100% precise.


    ---------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Gosub and Return are good friends...

    As long as you have a GOSUB... you can insert 2789423564875634275624365 432956345634564326586324957243657 234596243652 43656243756243654 356437856 46582436587243657 26435726435 2436 (+/- 1) goto in-between. And when you'll use Return, it will return just under the GOSUB.
    Last edited by mister_e; - 18th November 2006 at 20:11.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer
    I thought that once the program jumps, then it will forget where it was and will return to an unknown place. So that it will never be 100% precise.
    To be even more specific, the GOSUB will put a return address on the top of the "Stack" It will remain there forever (as long as the PIC is not reset) until a RETURN is executed. So, Steve's 2.7894235e+128 GOTOs do nothing to modify the address on the top of the stack. And, no matter when the RETURN is executed, the program will return to that address.

    HTH,
    Steve B
    Last edited by SteveB; - 18th November 2006 at 20:17.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default That's a better explanation indeed !!!

    SteveB....SteveB....SteveB....
    SteveB....SteveB....SteveB....
    Whizzz... Woohoo...
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1198&stc=1&d=116388100 4">
    Attached Images Attached Images  
    Last edited by mister_e; - 18th November 2006 at 20:25.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    So much for my fancy reply. Too slow.

    Got it Sayzer??
    DT

  7. #7
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor
    So much for my fancy reply. Too slow.
    Ahhhhhhh , I was really looking forward to it. My stab at it was just a down and dirty continuation of what Steve was getting at. We'll let Sayzer and Ryan weigh in on whether it worked for them.

  8. #8
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Steve,
    ROFL, Great picture!

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Hehe, Rock and roll, DEVIL!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  10. #10
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    I have a new teacher now!

    Thanks for this simple and clear explanation SteveB.

    I was expecting DT to come up with really complex explanations. heheh


    --------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  11. #11
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    mmm... not complex Sayzer, let's say detailled.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  12. #12
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Lightbulb

    Yep... makes sense. After all of your responses and looking at the manual for BranchL...
    Quote Originally Posted by TFM
    ...Index selects one of a list of Labels. Execution resumes at the
    indexed Label
    . For example, if Index is zero, the program jumps to the
    first Label specified in the list, if Index is one, the program jumps to the
    second Label, and so on. If Index is greater than or equal to the
    number of Labels, no action is taken and execution continues with the
    statement following the BRANCHL.
    ....(hence the RETURN)
    I guess seeing that return in Darrel's code was throwing me off, but now it I see why it's in there. It looked to me like a way of nesting subroutines. Both of the Steves explainations of how the return address in the stack works answers one of the questions I didn't even ask.... scary! Thankyou all.
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts