PDA

View Full Version : Gosub - clear stack



cburtis
- 8th July 2008, 06:27
Hi,
Sorry if this has been answered elsewhere. I did several searches and did not see an answer.

I have a project that “needs” to watch for a button push or an interrupt pin and react as soon as either happens. Instead of using interrupts (I didn’t want to use them because there is a lot of serial involved in this project) I decided to use a routine instead of pause called lull.

lull:
for lull_tmp = 1 to lull_time
pause 2
IF MOD_INT = 0 Then goto incoming
Button SET_BTON,0,255,0,B0,1,setdatetime
next lull_tmp
return

it is called with something like

lull_time = 2500 : gosub lull

so any time I need to pause I call lull.

I saw what looks like an issue and I think I understand where it is coming from.
Most of the code is based on subroutines (gosub/return) and I think when an interrupt is seen and the code uses the goto it does this sometimes in the middle of a subroutine (gosub). In other words it gets there by a gosub but never uses a return. I believe there is a section of code where I get to lull by a gosub then goto to incoming which has a return in it which sends it back to the original gosub that brought it to lull in the first place. My goal is for the interrupt or button press to goto their respective code and clear all of the gosubs in the stack. Is there anyway to do this?
Hopefully this makes sense.

Thanks in advance for any guidance.

Chris

sayzer
- 8th July 2008, 07:46
You may want to use SELECT CASE and divert your program with GOTO.

Thus, you get no return address in stack.

----------------------------