Hi, Just to re-iterate. All I ever said was that it can be "handy" to flush the stack and that in a controlled environment can solve some difficult problems like Abrupt Call Path exit which can be used for Exception Handling in a controlled environment. I never said it was a pop, and only ever pointed it out as a 'trick' to gain some control over the stack. Regards, James Caska caska@virtualbreadboard.com ujVM - 'The worlds smallest java virtual machine' -----Original Message----- From: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Olin Lathrop Sent: Monday, 8 October 2001 11:47 PM To: PICLIST@MITVMA.MIT.EDU Subject: Re: [PIC]: > OKNowAbruptlyExitTheCallPath > MOVLW .5 ;The trick is to know your call depth (MaxDepth-CurrentDepth) > MOVWF StackDepth > FlushStackLoop > DECFSZ StackDepth,F > CALL FlushStackLoop > GOTO MAIN.OnException.AbruptHandler All you are really doing here is a GOTO to a fixed address, which has to be in top level code. All the stack diddling is just a waste of time. It doesn't matter what's on the stack as long as you don't intend to return to any of it. It seems you want to "reset" the stack pointer. The stack is circular, so you can "reset" the stack any time you like just be deciding never to return to any called-from routine, which you have to do anyway if you were able to "empty" the stack. Your entire OKNowAbruptlyExitTheCallPath routine could be replaced by the single GOTO MAIN.OnException.AbruptHandler with no effect on the program. Your other example was jumping to an exception handler, then continuing to return to higher call levels from there. That can't be done on a 16F877 by stack manipulation alone. The example here only works because the exception handler is not nested inside a subroutine you intend to return from. > RETURN ;Never Reach Here > > CallWithAbruptExitDepth3 ;Build up a stack path > CALL OKNowAbruptlyExitTheCallPath > RETURN ;Never Reached > > CallWithAbruptExitDepth2 > CALL CallWithAbruptExitDepth3 ;Build up a stack path > RETURN ;Never Reached > > CallWithAbruptExitDepth1 > CALL CallWithAbruptExitDepth2 ;Build up a stack path > RETURN ;Never Reached > > > CallWithRegularReturn > ;Code Here > RETURN > > MAIN > CALL CallWithAbruptExitDepth1 > MAIN.OnException.AbruptHandler > CALL CallWithRegularReturn > > GOTO MAIN > > END ******************************************************************** Olin Lathrop, embedded systems consultant in Littleton Massachusetts (978) 742-9014, olin@embedinc.com, http://www.embedinc.com -- 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