如何EAX店返回值的大小比4个字节更大? [英] How can eax store return value of which size is bigger than 4 bytes?

查看:164
本文介绍了如何EAX店返回值的大小比4个字节更大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EAX用于函数存储返回值在32位平台上,我只是想知道,如果一个函数的返回值的大小大于4个字节,如何EAX处理呢?在这种情况下,操作系统可以保存返回值的堆栈上,并存储在EAX堆栈的地址,但随后的OS如何可以告诉存储在EAX中的值是否是一个地址的返回值或实际是返回值本身?

EAX is used to store return value of function in 32bit platform, I just wonder if the size of return value of a function is bigger than 4 bytes, how does eax handle it? In this case OS can save the return value on the stack and store the address of the stack in EAX, but then how can OS tell whether the value stored in EAX is an address to the return value or is actually the return value itself?

推荐答案

调用者和被调用有什么寄存器和堆栈包含同意。这就是所谓的调用约定,这就是所谓的的应用程序二进制接口(ABI)。被叫定义它希望如何被调用(的参数是否需要在栈上,在寄存器等)和编译器保证了code将其与主叫生成符合规定约定。

The caller and callee have to agree on what the registers and stack contain. This is called the calling convention, which is part of a larger concept called the application binary interface (ABI). The callee defines how it wants to be called (ie. whether arguments need to be on the stack, in registers, etc.) and the compiler ensures that the code it generates complies with the calling convention.

至于您的具体问题,这取决于ABI的。有时,如果返回值是大于4个字节,但不大于8个字节,它可以分成EAX和EDX。但大多数时候主叫函数将刚刚分配一些存储器(通常上堆叠)和一个指针传递给该领域所调用的函数。

As for your specific question, it depends the ABI. Sometimes if the return value is larger than 4 bytes but not larger than 8 bytes, it can be split into EAX and EDX. But most of the time the calling function will just allocate some memory (usually on the stack) and pass a pointer to this area to the called function.

还要注意的是OS的作用并不像你似乎认为一样重要。用不同的调用约定的二进制文件可能共存于同一系统上,和二进制文件甚至​​可以在内部使用不同的调用约定。操作系统的ABI是唯一重要的,当二元调用它的系统库。

Note also that the role of the OS is not as important as you appear to think. Binaries with different calling conventions may coexist on the same system, and binaries can even use different calling conventions internally. The ABI of the OS is only important when the binary calls its system libraries.

这篇关于如何EAX店返回值的大小比4个字节更大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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