Reputation: 8608
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?
Upvotes: 7
Views: 22458
Reputation: 642
RTE or RTI takes minimal context from top of the stack, while RTS takes return address (from top of the stack)
Upvotes: 0
Reputation: 71
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
Upvotes: 0
Reputation: 11
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
Upvotes: 1
Reputation: 3284
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.
Upvotes: 3
Reputation: 12457
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.
Upvotes: 1
Reputation: 71606
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.
Upvotes: 4
Reputation: 22989
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.
Upvotes: 1