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 ----- > From: "James Hillman" > To: > Sent: Monday, February 25, 2002 3:15 AM > 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 ? > > > > 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 > > mailto:piclist-unsubscribe-request@mitvma.mit.edu > > > > > > -- > http://www.piclist.com hint: To leave the PICList > mailto:piclist-unsubscribe-request@mitvma.mit.edu > -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu