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?


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.

  • Thakns for you response @dwelch .....the flag that return from interrupt pop out is related to what??? – Amit Singh Tomar Mar 13 '11 at 8:15
  • 1
    @AMIT: the flags (content of Processor Status Word) poped at RTI are the ones that were pushed at the start of the interrupt by the processor. This is, however, not automatically the case for all archtetures: Good old Z80 or 8051 architecture do NOT push the PSW at interrupts. In those cases the code of the iterrupt handler has to take care of it. – Curd Mar 13 '11 at 13:14
  • @AMIT @Curd That is why I started with the word Usually, I should have been a little less subtle. You did not specify an architecture so I had to be a bit general. Architectures that do not have a difference between return from interrupt and return from subroutine often do not have separate instructions. when they do it is usually something like popping the status word or for changing an internal processor protection state or something like that. – old_timer Mar 13 '11 at 14:38

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.


Well, interrupts are stored in a different code segment, so RTI are called with a far-call, while subroutines usually stays in the same code segment as the main program, so they're called with a near-call. The difference is that far-calls push the segment and the offset as return address, while near-calls push only the offset.


The fact that a processor is handling an interrupt is marked in one or more flags in the status register of a CPU.

This is needed, e.g. to mask other potential interrupts.

In order to tell the processor that interrupt handling is over and the flag can be reset, the RTI instruction is used instead of just RTS.

Of course the details depend on the particular CPU.

  • I would like to add that in many architectures additional information is pushed on the stack and so the stack frame has a slightly different layout in the interrupt routine. – Gunther Piez Mar 11 '11 at 11:33
  • It is not "marked" as you call it. If it is a hardware interrupt the interrupt bit will be set to disabled. However this can be caused by "normal" processing so it is no reliable indicator of an interrupt in progress. – Olof Forshell Mar 11 '11 at 21:24
  • @Olof Forshell: Seems you are thinking about one particular architecture. Since AMIT didn't refer to a particular architecture I just outlined the general behaviour that is common or similar to all architecures I know. Of course there are more details, as I mentioned. – Curd Mar 12 '11 at 21:39

RET will just pop the two bytes to PC (Addr low and Addr High) RETI will reset the interrupt enable flipflop and two bytes will be poped from the stack

RET:  pop ip ; its "brother" is *near* CALL - to the same segment 

RETF: pop ip ; *far* CALL - there's return path of segment and offset on the 
      pop cs ;  stack 

IRET: pop ip ; INT - this instruction PUSHes *three* registers on stack: 
      pop cs ; IP, CS, and FLags 
      pop fl ; well, in fact as for the stack operation INT is similiar 
             ; to far CALL but with the FL put on the stack 
  • 3
    Question was about RTI and RTS, they are for architectures other than x86. RET/IRET are x86/x86-64 – Michael Petch Mar 19 '18 at 9:59

Your Answer

