JUMP和CALL之间的区别 [英] Difference between JUMP and CALL

查看:449
本文介绍了JUMP和CALL之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JUMP和CALL指令有何不同?它与更高级别的概念(如GOTO或过程调用)有何关系? (我在比较中正确吗?)

How is a JUMP and CALL instruction different? How does it relate to the higher level concepts such as a GOTO or a procedure call? (Am I correct in the comparison?)

这就是我的想法:

JUMP或GOTO是一个将控件转移到另一个位置,并且控件不会自动返回到调用它的位置。

JUMP or GOTO is a transfer of the control to another location and the control does not automatically return to the point from where it is called.

另一方面,CALL或过程/函数调用返回到其调用点。由于其本质上的这种差异,语言通常使用堆栈,并且将堆栈框架推入以记住该位置以针对每个调用的过程返回。此行为也适用于递归过程。如果发生尾部递归,则无需为每个调用分别推堆栈帧。

On the other hand, a CALL or procedure/function call returns to the point from where it is called. Due to this difference in their nature, languages typically make use of a stack and a stack frame is pushed to "remember" the location to come back for each procedure called. This behaviour applies to recursive procedures too. In case of tail recursion, there is however no need to "push" a stack frame for each call.

您的答案和评论将是

推荐答案

如果您谈论的是x86汇编中的CALL / JMP或类似的东西,那基本上是对的。主要区别在于:

You're mostly right, if you are talking about CALL/JMP in x86 assembly or something similar. The main difference is:


  • JMP无需执行任何其他操作即可跳转到某个位置

  • CALL将当前指令指针推入堆栈(而不是:在当前指令之后一个),然后将JMP推入该位置。使用RET,您可以回到原来的位置。

通常,CALL只是使用JMP实现的便捷功能。您可以执行以下操作:

Usually, CALL is just a convenience function implemented using JMP. You could do something like

          movl $afterJmp, -(%esp)
          jmp location
afterJmp:

代替CALL。

这篇关于JUMP和CALL之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆