James Hillman 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 -- aiw@cypress.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 mailto:piclist-unsubscribe-request@mitvma.mit.edu