Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between return from interrupt(RTI) and return from subroutine(RTS)

I would like to know what is difference between return from interrupt(RTI) and return from subroutine(RTS). Are both are the same or there is any difference between these two?

like image 384
Amit Singh Tomar Avatar asked Mar 11 '11 08:03

Amit Singh Tomar


People also ask

What is return from interrupt?

To return from interrupt is to return code execution to the point it was at before the interrupt has occurred along with saving flags into flag register. Usually when an interrupt occurs, t is handled by calling its respective service routine.

What is the difference between interrupt and polling?

The main difference between interrupt and polling is that, in the case of an interrupt, the system informs the CPU that it needs attention, while talking about polling, the CPU constantly inspects the status of the system to find whether it needs attention.

What is interrupt subroutine?

Interrupt routines are generally used with Immediate elements, for example to turn an output ON in case of an alarm or emergency. To call an interrupt routine: Include an Interrupt subroutine of the correct name in your program; the subroutine is executed automatically when the condition for calling it is filled.

What does RTI do in assembly?

RTI (short for "ReTurn from Interrupt") is the mnemonic for a machine language instruction which returns the CPU from an interrupt service routine to the "mainline" program that was interrupted.


2 Answers

Usually return from interrupt restores the flags so that the interrupted code can continue to execute properly. Return from subroutine does not need to do that instruction is used intentionally in that flow of code and known that the flags are or are not destroyed depending on the architecture. In architectures that use a stack for the return address it is very apparent. A return from interrupt will pop the flags then the return address where a return from subroutine will pop only the return address.

like image 188
old_timer Avatar answered Nov 03 '22 00:11

old_timer


When a hardware interrupt occurs on an x86 the flags and return code segment+offset are pushed onto the stack. Then interrupts are disabled. This is to set the stage for the interrupt routine to service the interrupt: switch stacks or whatever it wants to do before either re-enabling interrupts and processing some more before/or returning from the interrupt. The iret instruction pops the previously saved flags (including the interrupt flag which was originally enabled) and the return location so that the interrupted routine can continue processing none the wiser.

like image 37
Olof Forshell Avatar answered Nov 03 '22 00:11

Olof Forshell