Gosub Interrupt

BeanieBots

Moderator
Are there any 'gotchas' waiting in the wings if I were to issue a "Gosub Interrupt".
eg, what would happen if a genuine interrupt occurred whilst in there?
Is there any stack manipulation (besides the normal gosub) on account of the keyword "Interrupt" being used.

Alternatively, could I force an interrupt by using setintflags and then manually setting the flag in code?
 

hippy

Ex-Staff (retired)
If you're in 'Interrupt:' and an interrupt occurs, execution will continue from "Interrupt:" and on return continue from where you were previously within "Interrupt:". As long as you code it for re-entrancy you'll be okay but if not you'll have problems with variables being overwritten etc. There's no stack manipulation other than the invisible GOSUB.

I think the safest bet is to use SETINTFLAGS and force it that way - or disable interrupts around the GOSUB to Interrupt.
 

boriz

Senior Member
SETINTFLAGS seems to only be available on X1 and X2 parts. I use GOSUB Interrupt at the beginning of the program to start the polling. Saves having two identical SETINT commands. Dunno if it’s any better. Just prefer it :)

Interesting question though.
 

BeanieBots

Moderator
Thanks, I was more concerned if anything else happened over and above the standard gosub manipulation which thankfully does not.
Re-entrant code is a little tricky in the PICAXE environment so I'll take the (with hindsight) obvious advice and dissable interrupts prior to gosub.

Forcing interrupts with setintflags is not an option in this particular app as flag integrity is required but certainly one to note for future situations.
 

boriz

Senior Member
Suppose all you need is a SETINT OFF command just prior to the GOSUB. Though beginning the subroutine with SETINT OFF might work just as well, and potentially save some bytes if you have more than one call in the main code. Interrupts should already be re-enabled at the end of the subroutine. Can’t help thinking this interrupting the interrupt idea might potentially furnish some interesting tricks.
 
Top