汇编语言中堆栈指针使用的查询
我已经准备好在维基百科上发布关于尾递归的文章: http://en.wikipedia.org/wiki/ Tail_call
现在,在本文的末尾,该示例显示堆栈指针用于访问传递给汇编伪代码中的函数调用的参数。这不是错了吗?我的意思是被调用者通过使用帧指针而不是堆栈指针来访问参数?
I was ready a article posted on wikipedia on Tail recursion: http://en.wikipedia.org/wiki/Tail_call
Now here at the end of the article, the example shows Stack Pointer being used to access the arguments passed to the function call in the assembly pseudo code. Isn't this wrong? I mean the arguments are accessed by the callee by using the frame pointer right rather than the stack pointer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用堆栈指针就可以了。毕竟它总是指向堆栈。如果函数中有任何压入或弹出指令,那么跟踪从堆栈指针到函数参数的偏移量会有点困难。当没有帧指针时,在调试器中将堆栈返回确实很困难。
使用帧指针可以使调试器和编译器编写者的工作变得更容易,但并不是必须有一个。
设置帧指针需要一条指令,并且它会占用一个可能用于其他用途的寄存器。因此使用堆栈指针是优化代码的常用技术。 Microsoft 编译器甚至为这种优化起了一个名字,他们称之为 帧指针遗漏
Using the stack pointer is fine. It always points to the stack after all. It's just a little difficult to keep track of offsets from the stack pointer to the function arguments if there are any push or pop instructions in the function. And it's really hard to walk the stack back in the debugger when there is no frame pointer.
Using a frame pointer make the job of the debugger and the compiler writer easier, but it's not necessary to have one.
Setting up the frame pointer takes an instruction, and it uses up a register that could potentially be used for other things. So using the stack pointer instead is a common technique for optimizing code. The Microsoft compilers even have a name for this optimization, they call it Frame Pointer Omission
专用的帧指针寄存器绝对是常见的 ABI 中更流行的调用约定,但没有什么当纯粹出于说明目的时,使用不同的(可能更简单的)调用约定本质上是“错误的”(向这些片段添加帧指针寄存器只会使它们更长一点并且不会改变任何实质性内容)。
A dedicated frame pointer register is definitely a more popular calling convention in common ABIs, but there's nothing intrinsically "wrong" in using a different (possibly simpler) calling convention when it's purely for illustrative purposes (adding a frame pointer register to those snippets would just make them a tad longer and change nothing substantial).