Does CLEAR Command clear return adrress of a subroutine?


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Hi, Paul

    There's also something Doable ( depends on use ...) :


    A GOSUB loads an address you can choose in the stack ...

    if ending the SUB with a GOTO instead of a RETURN ... This address will stay as the new "return", "retfie" ... address.

    That's used with the "RESUME Label" of PbP ...

    I do not think "clearing" the stack would be really useful ... as a stack containing zeros will cause the device to reset ONLY its program on the first "return or so" met ...

    Alain
    Last edited by Acetronics2; - 9th February 2008 at 17:12.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    As Alain mentioned, there are potential side effects If I start playing directly with the registers.

    Instead now, I am using flags being set to zero before going to a subroutine, and set the flags if something inside the subroutine is used.

    Then at the end of the subroutine(s), I am using a kind of select case with "GOTO".

    This way, I don't have any "return" address to care for.


    This is a little code eating though; but a lot safer.

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

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    As Alain mentioned, there are potential side effects If I start playing directly with the registers.
    Instead now, I am using flags being set to zero before going to a subroutine, and set the flags if something inside the subroutine is used.
    Then at the end of the subroutine(s), I am using a kind of select case with "GOTO".
    This way, I don't have any "return" address to care for.
    This is a little code eating though; but a lot safer.
    -------------------
    How about something like this:
    Code:
    main:
    code....code...code...
    addrreturn = 1
    goto subroutine
    
    return1:
    addrreturn = 2
    goto subroutine
    
    return2:
    addrreturn = 0
    goto main
    
    subroutine:
    code....code....code
    branch addrreturn , [ return1 , return2, return3.................]
    Set your branch return location parameter, jump to the generic subroutine, branch back to wherever it came from. No calls, no gosubs, and so on...

  4. #4
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    Instead now, I am using flags being set to zero before going to a subroutine, and set the flags if something inside the subroutine is used.

    Then at the end of the subroutine(s), I am using a kind of select case with "GOTO".

    This way, I don't have any "return" address to care for.

    Hi SAYZER,

    I do not get what you mean by "return" address care ... why can't you just match each "gosub" with a "return" and let PBP do the work.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

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


    Did you find this post helpful? Yes | No

    Default

    In the code, I jump from locations to locations really very fequently.

    I am having a lot of return addresses.
    _________________________________
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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


    Did you find this post helpful? Yes | No

    Default

    Ok, here is a simple example good enough to explain the issue.

    Code:
    <font color="#000000">Begin:
    
    OK = <font color="#FF0000"><b>0
    
    
    </b></font>MainMenu:
    <font color="#000080"><i>'...stuff is going on here...
    
        </i><b>IF </b></font>OK = <font color="#FF0000"><b>1 </b></font><font color="#000080"><b>THEN GOSUB </b></font>PrintMemory
    
    
        <font color="#000080"><b>GOTO </b></font>MainMenu
        
        
    PrintMemory:
        <font color="#000080"><b>IF </b></font>Memory = <font color="#FF0000"><b>0 </b></font><font color="#000080"><b>THEN </b></font>Begin
        <font color="#000080"><b>RETURN    </b>
    <i>' IF this IF statement is true, then I get a useless Return address on Stack,
    and I get a lot of them.
    </i></font>
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    Ok, here is a simple example good enough to explain the issue.
    ...........
    If you're careful, and I mean very, very careful, you could turn off the Stack Overflow/Underflow reset bits in the CONFIG and just not worry about the RETURN addresses...let them overflow as they will.
    But again, you'd have to be very careful, especially if you nest any GOSUB's at all...so that might not work out at all.
    Maybe take DT's Software Gosub example shown earlier and add your own subroutine to POP the last GOSUB address off the Software Stack.

    Actually, I just looked at the code for the first time...
    In the swStack.inc file, you could use this section:

    Code:
    '------------Pop Address from the Stack---------------------------------------
    Pop:
        if StackPTR = 0 then  StackEmpty = 1  ; Update Empty status
        if StackEmpty = 0 then                ; If Stack isn't Empty
           Address = Stack[StackPTR-1]        ; Get last Address from the Stack
           StackPTR = StackPTR - 1            ; Point to Prior Stack level
           StackFull = 0                      ; 0 - Since we just removed 1
        else
           STunderflow = 1                    ; Stack was Empty on swReturn
        endif
        if StackPTR = 0 then  StackEmpty = 1  ; Update Empty status
    return
    You have access to the Pop subroutine.

    But I'm guessing here...since I haven't used to swGosub/swReturn routines at all.........

    You 'include' DT's software stack routines, your code above becomes:
    Code:
    Begin:
    OK = 0
    MainMenu:
    '...stuff is going on here...
        IF OK = 1 THEN
                   @ swGOSUB PrintMemory
        ENDIF
        GOTO MainMenu
    PrintMemory:
        IF Memory = 0 THEN
                   Gosub Pop  'regular Gosub here, generic, can be used system wide
                   Goto BEGIN    'no more return address from the Gosub above
        ENDIF
        swRETURN
    Again, I'm guessing...
    Last edited by skimask; - 19th February 2008 at 16:33.

Similar Threads

  1. 8x8 keypad matrix...
    By mbox in forum General
    Replies: 5
    Last Post: - 9th October 2014, 18:43
  2. Multiple RETURNS within a single subroutine
    By BrianT in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st June 2009, 16:43
  3. Interruptus Frustratus
    By Byte_Butcher in forum General
    Replies: 16
    Last Post: - 17th April 2009, 20:36
  4. Replies: 14
    Last Post: - 26th September 2007, 05:41
  5. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29

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