Searching \ for '[PIC]: is it ok to have stack underflow ?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'is it ok to have stack underflow ?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: is it ok to have stack underflow ?'
2002\02\25@065432 by James Hillman

flavicon
face
In my 16F628 program I call a subroutine that waits for an event to happen.
If the event does not happen within a certain length of time can I use a
goto instruction to restart the program from a known point, without using a
return instruction to pop the return address back off the stack ?
I know this will cause a stack underflow(?) condition, but since the stack
is a circular buffer surely it won't matter because subsequent calls will
have the required return to go with them - or will it ?

Start:
    call initialize
StartEnd:
    call setup
Mainloop:
    call Subroutine
    call sub2
    goto Mainloop

Subroutine:
    clrf counter
SubLoop:
    btfss Input1
    retlw 0x00
    btfss Input2
    retlw 0x01
    decfsz counter,f
    goto SubLoop
    goto StartEnd             ;timeout so restart again

Thanks,

James

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2002\02\25@070418 by Michael Rigby-Jones

flavicon
face
> -----Original Message-----
> From: James Hillman [SMTP:.....jamesKILLspamspam@spam@IND-INTERFACE.CO.UK]
> Sent: Monday, February 25, 2002 9:16 AM
> To:   PICLISTspamKILLspamMITVMA.MIT.EDU
> Subject:      [PIC]: is it ok to have stack underflow ?
>
> In my 16F628 program I call a subroutine that waits for an event to
> happen.
> If the event does not happen within a certain length of time can I use a
> goto instruction to restart the program from a known point, without using
> a
> return instruction to pop the return address back off the stack ?
> I know this will cause a stack underflow(?) condition, but since the stack
> is a circular buffer surely it won't matter because subsequent calls will
> have the required return to go with them - or will it ?
>
In this case it's fine.  As you say, the stack is circular so it dosen't
matter where the PIC starts pushing within the buffer.  Stack underflow is
more RETURNS than CALLS, so this is technicaly overflow, as you are
executing a CALL without the matching RETURN.

Mike

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam.....mitvma.mit.edu


2002\02\25@101119 by Lawrence Lile

flavicon
face
This sounds like skating on thin ice to me.  I would avoid it.  Maybe what
you really want to do is trigger a watchdog timeout, and restart the PIC for
real?

--Lawrence

{Original Message removed}

2002\02\25@102114 by Michael Rigby-Jones

flavicon
face
{Quote hidden}

> {Original Message removed}

2002\02\25@102321 by Byron A Jeff

face picon face
On Mon, Feb 25, 2002 at 09:09:21AM -0600, Lawrence Lile wrote:
> This sounds like skating on thin ice to me.  I would avoid it.  Maybe what
> you really want to do is trigger a watchdog timeout, and restart the PIC for
> real?

Lawrence, James' logic is perfectly correct. You can throw away the stack at
any time as long as you have no intention of accessing the previous data
from the stack.

Just as long as after the jump the code doesn't do a return/retlw before
doing a call everything is fine.

Note that StartEnd immediately does a subroutine call. So the return stack
is instantly reset.

This will work with absolutely no problem.

BAJ
>
> --Lawrence
>
> {Original Message removed}

2002\02\25@150703 by Olin Lathrop

face picon face
> In my 16F628 program I call a subroutine that waits for an event to
happen.
> If the event does not happen within a certain length of time can I use a
> goto instruction to restart the program from a known point, without using
a
> return instruction to pop the return address back off the stack ?

Yes.  I've done this.  In one case I used the RB0 interrupt as an externally
forced GOTO 4.

> I know this will cause a stack underflow(?)

Overflow, actually, but that is only from the debugger's point of view.

> condition, but since the stack
> is a circular buffer surely it won't matter because subsequent calls will
> have the required return to go with them

Right.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, @spam@olinKILLspamspamembedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
KILLspampiclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2002\02\25@150706 by Olin Lathrop

face picon face
> This sounds like skating on thin ice to me.  I would avoid it.  Maybe what
> you really want to do is trigger a watchdog timeout, and restart the PIC
for
> real?

As long as you understand what is happening and the code is properly
documented, I don't see why this is "skating on thin ice".


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, RemoveMEolinTakeThisOuTspamembedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
spamBeGonepiclist-unsubscribe-requestspamBeGonespammitvma.mit.edu


2002\02\25@165249 by uter van ooijen & floortje hanneman

picon face
> In my 16F628 program I call a subroutine that waits for an event to
happen.
> If the event does not happen within a certain length of time can I use a
> goto instruction to restart the program from a known point, without using
a
> return instruction to pop the return address back off the stack ?
> I know this will cause a stack underflow(?) condition, but since the stack
> is a circular buffer surely it won't matter because subsequent calls will
> have the required return to go with them - or will it ?

Stack overflow is never a problem, it is the stack underflow (that in most
cases unavoidably follows a stack overflow) that is the problem. But what
you describe is one of the specialised uses of stack overflow that does not
cause a later underflow (because you skip a return), so this use ie
perfectly OK.

Wouter van Ooijen
--
Van Ooijen Technische Informatica: http://www.voti.nl
Jal compiler, Wisp programmer, WLoader bootloader, PICs kopen

--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-requestEraseMEspamspam_OUTmitvma.mit.edu


2002\02\25@165257 by uter van ooijen & floortje hanneman

picon face
> The position of the stack
> pointer within the stack is completely unknown at power up

It is easier to regard the pic stack as not having a stack pointer but as a
chain of registers. Maybe it is even implemented that way. Consider a shelve
of 8 books. You can add one at the right side, and the leftmost book will
fall of the shelve and is lost forever. You can take off the rightmost and a
magic copying machine duplicates the leftmost book. There are ALWAYS exactly
8 books on the shelve. The pic starts with 8 'random' books. A wise man does
not return to one of these books.

Wouter van Ooijen
--
Van Ooijen Technische Informatica: http://www.voti.nl
Jal compiler, Wisp programmer, WLoader bootloader, PICs kopen

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestspamTakeThisOuTmitvma.mit.edu


2002\02\25@195254 by Andrew Warren

flavicon
face
James Hillman <PICLISTEraseMEspam.....mitvma.mit.edu> wrote:

> In my 16F628 program I call a subroutine that waits for an event to
> happen. If the event does not happen within a certain length of time
> can I use a goto instruction to restart the program from a known
> point, without using a return instruction to pop the return address
> back off the stack ? I know this will cause a stack underflow(?)
> condition, but since the stack is a circular buffer surely it won't
> matter because subsequent calls will have the required return to go
> with them - or will it ?

James:

As others have said, it'll work fine.  If you try debugging your code
on one of Microchip's emulators, however, you may have problems.  At
the very least, you'll have to disable the "stack overflow/underflow"
warning, and -- depending on which emulator you use -- you may have
to change the code to avoid the overflow.

Speaking of which... Why not change your code to avoid the overflow,
anyway?  You only need to add 5 lines and remove one, and you'll end
up with a subroutine that behaves as most people would expect it to:

Mainloop:
    call Subroutine
    BTFSC TIMEOUT    ;*** ADD
    GOTO  StartEnd   ;*** ADD
    call sub2
    goto Mainloop

Subroutine:
    BCF  TIMEOUT     ;*** ADD
    clrf counter
SubLoop:
    btfss Input1
    retlw 0x00
    btfss Input2
    retlw 0x01
    decfsz counter,f
    goto SubLoop

    BSF   TIMEOUT    ;*** ADD
    RETLW 0x02       ;*** ADD

    ;*** REMOVE goto StartEnd ;timeout so restart again

-Andy

=== Andrew Warren -- EraseMEaiwspamcypress.com
=== Principal Design Engineer
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestEraseMEspamEraseMEmitvma.mit.edu


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