__stdcall替代方案 [英] __stdcall alternative
问题描述
我正在混合使用C和ASM,并且为了从C调用ASM,我恰好使用了
__stdcall约定(使用C约定对其他人来说不实用
原因)。
但是,__ stdcall似乎假设机器寄存器是由
调用的例程保存的(据我所知,我可以收集一些小时搞乱一些
奇怪的行为,特别是使用优化的C代码)。
是否还有其他我可以使用的通话约会
可用?
或者有没有办法指定外部函数不能保存
寄存器或表现不佳?
-
谢谢,
Bartc
I''m mixing C and ASM, and for calling ASM from C, I just happened to use the
__stdcall convention (using C convention is not practical for other
reasons).
But, __stdcall seems to assume that machine registers are saved by the
called routine (as far as I can gather after a few hours messing with some
strange behaviours especially with optimised C code).
Is there any other call convention I can use likely to be commonly
available?
Or is there a way of specifying that an external function does not save
registers or is badly behaved?
--
Thanks,
Bartc
推荐答案
Bartc写道:
Bartc wrote:
我正在混合使用C和ASM,而从C调用ASM,我恰好使用了
__stdcall约定(使用C约定对其他人来说不实用) r $>
原因)。
I''m mixing C and ASM, and for calling ASM from C, I just happened to use the
__stdcall convention (using C convention is not practical for other
reasons).
什么是__stdcall?它不是C,所以它必须是特定于平台的,为你的平台尝试一个
组,你会得到更多的帮助。
-
Ian Collins。
What is __stdcall? It''s not C, so it must be platform specific, try a
group for your platform, you''ll get more help there.
--
Ian Collins.
Bartc写道:
Bartc wrote:
我''混合C和ASM,并从C调用ASM,我恰好使用了
__stdcall约定(使用C约定对其他
原因不实用)。 br />
但是,__ stdcall似乎假设机器寄存器是由
调用例程保存的(据我所知,几个小时后我可以收集一些事情/>
奇怪的行为,尤其是优化的C代码)。
I''m mixing C and ASM, and for calling ASM from C, I just happened to use the
__stdcall convention (using C convention is not practical for other
reasons).
But, __stdcall seems to assume that machine registers are saved by the
called routine (as far as I can gather after a few hours messing with some
strange behaviours especially with optimised C code).
很明显你应该保存编译器认为永久的寄存器
在windows下(通常使用stdcall)你应该保存
(我假设64位CPU)
rsi
rdi
rbx
r12-r15
rbp
最后你应该发出一个
ret
OBVIOUSLY you should save the registers ytour compiler thinks are permanent
Under windows (where stdcall is commonly used) you should save
(I am assuming 64 bit CPU)
rsi
rdi
rbx
r12-r15
rbp
And at the end you should issue a
ret
8
$例如,当你收到8个字节的参数时,b $ b。
8
when you receive 8 bytes of arguments for instance.
是否还有其他我可以使用的调用约定
可用?
Is there any other call convention I can use likely to be commonly
available?
你也可以使用C调用约定。保存
的寄存器是相同的但是你应该发出
ret
并且被调用的程序调整堆栈。 br />
you could just as well use the C calling convention. The registers to save
are THE SAME but you should just issue
ret
and the called procedure adjusts the stack.
或者是否有一种方法可以指定外部函数不保存
寄存器或表现不佳?
Or is there a way of specifying that an external function does not save
registers or is badly behaved?
没有办法做到这一点。你必须保存这些,如果不是
你就会崩溃。
There is NO way to do that. YOU HAVE TO SAVE THOSE if not
you will just have a crash.
>
>
-
jacob navia
jacob at jacob point remcomp point fr
logiciels / informatique
http://www.cs.virginia .edu / ~lcc-win32
这篇关于__stdcall替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!