C 函数的返回值到 ASM
我正在尝试从 ASM 中调用一个函数。我知道如何调用它,但我无法找到如何获取该函数的返回值。示例如下:
C 代码:
int dummy() {
return 5;
}
(N)ASM 代码:
dummyFunction:
call dummy
;grab return into eax
inc eax ; eax should be 6 now
ret
有什么想法吗?
I'm trying to call a function from within ASM. I know how to call it, but i'm having trouble finding how to get the return value of this function. An example follows:
C code:
int dummy() {
return 5;
}
(N)ASM code:
dummyFunction:
call dummy
;grab return into eax
inc eax ; eax should be 6 now
ret
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
返回值位于
eax
中。如果您从 asm 调用了 C 函数,则可以从eax
读取返回值。如果您尝试从 asm 函数返回到 C,请将预期的返回值存储在eax
中。返回浮点值、
long long
值或结构会变得更加复杂,因此请询问您是否需要这些,有人(也许是我)会帮助您。The return value is in
eax
. If you've called a C function from asm, you can read the return value fromeax
. If you're trying to return from an asm function to C, store the intended return value ineax
.Things get a little bit more complicated for returning floating point values,
long long
values, or structures, so ask if you need that and someone (maybe me) will help you.尽管答案足以回答OP的问题,但以下摘录涵盖了大多数情况 DJGPP 的联机帮助页 以确保完整性:
Although the answers are sufficient to answer the OP's question, here's an extract covering most cases from DJGPP's manpage for completeness:
这取决于平台和调用约定,但通常,如果返回值是基本类型或指针,则应该已经在 eax 中返回,并且在浮点寄存器 st(0)< 中/code> 如果它是浮点类型,我想。
It depends on the platform and the calling convention, but usually, the return value should already be returned in
eax
if it's a primitive type or pointer and in the floating point registerst(0)
if it's a floating point type, I think.