为什么函数参数比返回地址更早地推送到调用堆栈中? [英] Why are function parameters pushed earlier on call stack than the return address?

查看:162
本文介绍了为什么函数参数比返回地址更早地推送到调用堆栈中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自],同时使用几个由编译器创建的机器命令推送参数和变量。



因此,返回地址是最后一件事



所有参数都被推送到返回地址之前,因为跳转到实际函数并将返回地址插入堆栈是在同一条机器命令中完成的。



另外,另一个原因是-调用方是在堆栈上分配参数的空间-它[调用方]也应该是清理该空间的人。


From http://en.wikipedia.org/wiki/Stack_pointer#Structure

I am wondering why the return address for a function is placed above the parameters for that function?

It makes more sense to have Return Address pushed onto the stack before the Parameters for Drawline because the parameters are not required any more when the Return Address is popped for returning back to the calling function.

What are the reasons for preferring the implementation shown in diagram above?

解决方案

The return address is usually pushed via the call machine command, [which in the native language's instruction set] while the parameters and variables are pushed with several machine commands - which the compiler creates.

Thus, the return address is the last thing pushed by the caller, and before anything [local variables] pushed by the callee.

The parameters are all pushed before the return address, because the jump to the actual function and the insertion of the return address to the stack is done in the same machine command.

Also, another reason is - the caller is the one allocating space on stack for the parameters - It [the caller] should also be the one who cleans it up.

这篇关于为什么函数参数比返回地址更早地推送到调用堆栈中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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