Searching \ for 'Using a goto to terminate a function.' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/index.htm?key=using+goto+terminate
Search entire site for: 'Using a goto to terminate a function.'.

Truncated match.
PICList Thread
'Using a goto to terminate a function.'
1999\03\28@194142 by Steve Ridley

flavicon
face
PIClisters

I have a question regarding the use of a goto rather than a return to
terminate a function call. In certain circumstances I could save a lot of
code if I could terminate functions by just going to a general clean up area
and then back to my main loop without ever returning to the place the
function was called from. This means I am leaving the return address on the
stack. What if any are the implications of doing this ? Is there some other
way to achieve this ? Will the stack overflow or will it not matter because
the unused return addresses eventually get pushed off the end of the stack?
Does the PIC do anything when a stack overflow condition occurs ?

Steve Ridley
Blue Ocean Telecommunications
Sydney,  Australia

1999\03\28@200012 by Tony Nixon

flavicon
picon face
Steve Ridley wrote:

> I have a question regarding the use of a goto rather than a return to

The stack pointer will just wrap around on overflow or underflow.

As long as you know what is going on there shouldn't be a problem.

The simulators might complain though.

--
Best regards

Tony

PicNPoke - Multimedia 16F84 Beginners PIC Tools.
*** FREE PCB OFFER ***

http://www.picnpoke.com
Email spam_OUTpicnpokeTakeThisOuTspamcdi.com.au

1999\03\28@200818 by Regulus Berdin

picon face
Hi,

How about just calling the function also using GOTO.  This way, the
stack is untouched.

regards,
Reggie

Steve Ridley wrote:
{Quote hidden}

--
e-mail: .....rberdinKILLspamspam@spam@bigfoot.com
ICQ#:   31651436
URL:    http://www.bigfoot.com/~rberdin

1999\03\28@221945 by Wagner Lipnharski

picon face
There were a simple technique used when you don't have stack to save the
return address and you need to call the same routine from different
other routines.  It was used in an old 3270 IBM Keyboard that used a Z80
without any external RAM. The trick is to "name" each caller routine
with a code number.  When the caller jumps to the subroutine, first it
stores its "identification" at one internal registers defined just for
that purpose, you can call it "id" register.  All subroutines "called"
(jumped into) using this technique just jump back to a "common return"
routine. This routine looks into that "id" register and based on a
address table it jumps back to the original "caller" (jumper) routine.
Using one byte register as the "id", it is possible to name 256
different "caller" routines, obviously. It is pretty odd, takes few
extra bytes in the code, but works pretty well and doesn't need a stack
at all.

I use to write some code that sometimes it needs to abort the operation
in the middle of several calls deep into the stack, as for example;
communication timeouts. Sometimes it takes more code just to control how
much the stack is deep to get it back to the right level before jump
back to the main level abortive routine.  The best thing to do is just
forget the stack pointer, jump back to the main loop and reinitialize
the stack to the fresh start address.  As it would be aborted anyway, it
doesn't matter to keep control of the calls and returns.

Steve Ridley wrote:
{Quote hidden}

1999\03\29@014903 by Vincent Deno

flavicon
face
> Steve Ridley wrote:
> >
> > PIClisters
> >
> > I have a question regarding the use of a goto rather than a return to
> > terminate a function call. In certain circumstances I could save a lot of
> > code if I could terminate functions by just going to a general clean up area
> > and then back to my main loop without ever returning to the place the
> > function was called from. This means I am leaving the return address on the
> > stack. What if any are the implications of doing this ? Is there some other
> > way to achieve this ? Will the stack overflow or will it not matter because
> > the unused return addresses eventually get pushed off the end of the stack?
> > Does the PIC do anything when a stack overflow condition occurs ?
> >
> > Steve Ridley
> > Blue Ocean Telecommunications
> > Sydney,  Australia
>

I don't know if this corretly addresses your question but:

In several of my interrupt handling routines, I needed to perform several
of the same operations before returning (from different subroutines of
course).  So I simply put them in a function (which also contains the
return) and jump to that routne from each subroutine.

Ex:

Sub1
       <code>
       jmp     Common

Sub2
       <code>
       jmp     Common

Common
       <code>
       return


--------------
Vincent Deno Design Engineer
Theta Digital Corp.
http://www.thetadigital.com
denovjspamKILLspamemail.uc.edu
_____________
| ____   ____ |
|/| | | | | |\|
| | |/| |\| | |
| | | | | | | |
| |_/ | | \_| |
| |   | |   | |
|_/  /___\  \_|

1999\03\29@125932 by Thomas McGahee

flavicon
face
I do this all the time. Usually on an error condition I do a goto the
initialization routine, so everything is placed in a known set of
conditions. I have never had any problems doing this.

Fr. Tom Mcgahee

----------
{Quote hidden}


'Using a goto to terminate a function.'
1999\04\02@120449 by Holger Morgen
flavicon
face
Hi -

Well your stack get filled, but that is not a problem, because it "operates
as a circular buffer" (Read the MC 16F8x manual on page 18. section 4.4)

But why not just call "return" when your cleanup thingy is done? (Call
funtion, function 'goto' to cleanup, cleanup returns to main.)

/holger
{Quote hidden}

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...