从中断返回(RTI)和从子程序返回(RTS)之间的区别

发布于 2024-10-21 13:29:40 字数 53 浏览 5 评论 0原文

我想知道从中断返回(RTI)和从子程序返回(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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

徒留西风 2024-10-28 13:29:40

通常从中断返回会恢复标志,以便被中断的代码可以继续正确执行。从子例程返回不需要这样做,该指令是在该代码流中有意使用的,并且知道标志是否被破坏,具体取决于体系结构。在使用堆栈作为返回地址的体系结构中,这一点非常明显。从中断返回将弹出标志,然后弹出返回地址,而从子例程返回将仅弹出返回地址。

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.

哥,最终变帅啦 2024-10-28 13:29:40

当 x86 上发生硬件中断时,标志和返回代码段+偏移量将被推送到堆栈上。然后中断被禁用。这是为中断例程服务中断奠定了基础:在重新启用中断并在/或从中断返回之前进行更多处理之前,切换堆栈或执行任何操作。 iret 指令弹出先前保存的标志(包括最初启用的中断标志)和返回位置,以便被中断的例程可以继续处理。

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.

2024-10-28 13:29:40

嗯,中断存储在不同的代码段中,因此 RTI 是通过远调用来调用的,而子例程通常与主程序位于同一代码段中,因此它们是通过近调用来调用的。 -称呼。区别在于远调用将段和偏移量作为返回地址推送,而近调用仅推送偏移量。

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.

习惯成性 2024-10-28 13:29:40

处理器正在处理中断的事实被标记在 CPU 状态寄存器中的一个或多个标志中。

这是必要的,例如屏蔽其他潜在的中断。

为了告诉处理器中断处理已结束并且可以重置标志,使用了 RTI 指令而不仅仅是 RTS。

当然,细节取决于特定的CPU。

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.

脸赞 2024-10-28 13:29:40

RET 只会将两个字节弹出到 PC(Addr low 和 Addr High)
RETI 将重置中断使能触发器,并从堆栈中弹出两个字节

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

半世晨晓 2024-10-28 13:29:40
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 
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 
云醉月微眠 2024-10-28 13:29:40

RTE 或 RTI 从堆栈顶部获取最小上下文,而 RTS 则从堆栈顶部获取返回地址

RTE or RTI takes minimal context from top of the stack, while RTS takes return address (from top of the stack)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文