jumping out of a gosub reminder


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: jumping out of a gosub reminder

    I had similar ideas, but give up on them. I use something like this:
    Code:
    Gosub xx : If err=1 then goto yy
    
    XX:
    if something to triger going to err sub then
    err=1 ' goto in different sub after retun
    else
    err=0 ' return and continue normally
    endif
    But if you must have gosub, without return, you can look up in datasheet of PIC, POP command. It should pop up stack, and free one space.

    Quote Originally Posted by Datasheet
    The TOS value is pulled off the return
    stack and is discarded. The TOS value
    then becomes the previous value that
    was pushed onto the return stack.
    This instruction is provided to enable
    the user to properly manage the return
    stack to incorporate a software stack
    If I understand POP and PUSH commands, you could do something like this

    If err=1 THEN
    @ POP
    GOTO ErrHandler
    ENDIF
    Last edited by pedja089; - 2nd February 2020 at 22:15.

  2. #2
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: jumping out of a gosub reminder

    Don't use both. What was printed in the above post will GOTO a new address, then erase the RETURN address. This will generate a Stack Underflow condition and the PIC will "exhibit unpredictable behavior". Just use GOTO and leave the Stack alone.

  3. #3
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: jumping out of a gosub reminder

    But if I understand correctly he want to goto and never return.
    So you need to pop stack to prevent overflow.

  4. #4
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: jumping out of a gosub reminder

    Then yes, POP the Stack. Not sure when such an approach might be considered good programming practice, though.

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,666


    Did you find this post helpful? Yes | No

    Default Re: jumping out of a gosub reminder

    Not sure when such an approach might be considered good programming practice
    using goto to control program flow = spaghetti code [hard to unravel ,hard to modify ]

    spaghetti code with stack popping to undo dead subs ?

    franken code ? [as in Frankenstein ]
    you would need good comments with a flow diagram and a state diagram at hand to unravel it
    Warning I'm not a teacher

  6. #6
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: jumping out of a gosub reminder

    Quote Originally Posted by richard View Post
    franken code ?
    Not necessarlly, Lot of hi level programing language have this already implemented. eg in .net: On Error GoTo, Try, catch, etc...
    Same could be done for HW. If something external happened then you need unconditionally goto something, and start program from known place.

    It is not easy to implement, by any means. But it could very useful.
    What longpole001 have exactly on his mind, I can't tell...

  7. #7
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: jumping out of a gosub reminder

    You could count your gosub nesting level in another variable.
    Increment for every gosub, and decrement for every return.
    You don’t know about PBP's own gosubs, but they are supposed to be the compiler’s problem, and aren’t your responsibility.

    So you would know if the value wasn’t zero when you thought it should be.

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,666


    Did you find this post helpful? Yes | No

    Default Re: jumping out of a gosub reminder

    Quote Originally Posted by pedja089 View Post
    Not necessarlly, Lot of hi level programing language have this already implemented. eg in .net: On Error GoTo, Try, catch, etc...
    hmm, in python at least a sub with a "try" still returns , even if the processing aborts and executes an "try" error routine.
    i see no goto or stack popping going on.

    a couple of python subs with try
    Code:
    def process_d(tname,q):    while exitflg==0:
            dx=ser.readline()
            try :
                rt='s'
                
                ff= string.rstrip(dx)   
                int(ff,16)   ##non hex chr will cause ValueError
                if dx[0]=='A':
                     rt='w'
                
                #print dx
                ts=str(datetime.datetime.now())[:19]
                r_x=[ts,dx,rt]
                queueLock.acquire()
                q.put(r_x)
                queueLock.release()
            except ValueError:
                    #print dx
                    dx=[]
    
    
    def bag_reading ():
        global readings
        bag_data_time =datetime.datetime.now()
        if len(readings)>0:
             
           try:
               conn=sqlite3.connect('/media/CORSAIR/wh2.db') 
               curs=conn.cursor()
               curs.executemany("INSERT INTO log values((?),(?),(?),(?))", (readings))
               # commit the changes
               conn.commit()
               conn.close()
               print 'write ',len(readings),'  ',readings[-1][0]
               readings=[]
               bag_data_time += datetime.timedelta(minutes=5)
           except sqlite3.OperationalError as err :
               print 'db busy',err
               bag_data_time += datetime.timedelta(minutes=1)  
        return   bag_data_time
    Warning I'm not a teacher

Similar Threads

  1. programming jumping game
    By bokken in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th February 2012, 06:40
  2. jumping out of subroutine with goto
    By helloo in forum General
    Replies: 4
    Last Post: - 3rd January 2012, 10:37
  3. OWIN not jumping to label
    By MOUNTAIN747 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th March 2011, 15:30
  4. A reminder for all Forum Users
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 40
    Last Post: - 6th December 2008, 18:56
  5. Pot reading jumping like crazy!!!
    By champion in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 20th November 2006, 21:24

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