Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Interrupt & going back to the same label

Status
Not open for further replies.

mabauti

Member
I want to going back to the same label after an interruption service ALWAYS

let´s say I have this program
Code:
...
decisions:

blablabla
yadayadayada
...

routine1:
dothat
dothis
goto routine1

routine2:
dothat
dothis
goto routine2

...

routine9001:
dothat
dothis
goto routine9001

end

How do I make an interruption service in order to go back ALWAYS to the label decisions?
 
You put the address of the label you want to return to on the stack. When you execute the return from interrupt you'll get where you want to go. I don't recommend this approach for two reasons.

  1. It is completely unnecessary
  2. You'll never remember what you did and why when you come bact to it in 6 months
 
It can also lead to really nasty bugs. Image if you have a 32bit add routine on an 8bit processor and it is half way through dumping the answer, 8bits at a time, into a 32bit variable and your interrupt routine calls it away never to return.
Use flags to do this.
 
In the case of no 32-bit add routine I guess its ok. Not a morality or legality thread.

I have code in products that after a certain criteria is meet in the interrupt, I must always vector to a know location period. This was not true for every time the interrupt was called but after being called a set number of times. If its need then do it, block interrupts during 32-bit routines or whenever necessary.

And whats the method of remember anything in code?
Code:
;Vector to Sub "Decision"
;Reasons follow below:
;1....
;2....
 
mabauti said:
How do I make an interruption service in order to go back ALWAYS to the label decisions?

This is not a debate of why you would need to do it but how to do it.

With AVR, this is easily done as one can modify the stackpointer or push/pop values from the stack.

With 16F PIC, it is a bit more involved. You need to place(sometimes more than one) check bit instructions inside every routine and jump to "decisions" every time the bit is found set. Inside the ISR, you set that bit and return.

On start executing the "decisions" code, you reset the bit to false.
 
eblc1388 said:
This is not a debate of why you would need to do it but how to do it.

I would disagree, if he's wanting to do such completely wrong things he needs telling NOW, not after he's created loads of really badly written and unreliable code. I don't see as there's any reason to ever want to do something so potentially dangerous?.
 
Back in the 80s it was quite normal to have you ISR jump to the start of your main loop. Your main loop processed all the critical game stuff before updating the screen. By placing things like updating the score and radars etc near the bottom of the main loop they would get "dropped" if things got too busy. No one ever noticed if the score/radar got updated because at this point they were too busy trying to stay alive. One classic that used this technique was Defender from Williams.

Anyway, on a 16 series pic you could simply do,

Code:
        org   4
        goto RequiredCode

The code at the destination would have to clear the interrupt flag and re enable the global interrupts. The stack is circular and so doesn't matter. I must however add, I can't think of many applications that would benefit from this technique. Edit, if the OP's different routines were LED flash sequences (or something similar) and the IRQ was to change sequence then I guess this would work.

Mike.
 
Last edited:
A more common method is to have the ISR set a flag and handle the branch back to decisions handled in the main code.

This mimics the action of a break within a loop.

Code:
decisions:
     startOver = false
     blablabla
     yadayadayada
     ...
     
     if (startOver is true) 
     then goto decisions

     call routine1
     if (startOver is true) 
     then goto decisions
     
     call routine2
     goto decisions
end


You could shorten up the code with a macro or define.
 
eblc1388 said:
This is not a debate of why you would need to do it but how to do it.

With AVR, this is easily done as one can modify the stackpointer or push/pop values from the stack.

With 16F PIC, it is a bit more involved. You need to place(sometimes more than one) check bit instructions inside every routine and jump to "decisions" every time the bit is found set. Inside the ISR, you set that bit and return.

On start executing the "decisions" code, you reset the bit to false.
And in that spirit I gave him the answer he was seeking along with the admonition. I feel that we have a responsibility to warn people to think about what they are doing. They can still do whatever they want -- that is the essence of freedom.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top