本文介绍了在gcc内联汇编中调用一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说,我想在gcc的内联汇编中调用带有以下签名的函数。我该怎么做? int some_function(void * arg);
解决方案
p>
void * x;
asm(..写入寄存器%0的代码:= r(x):...
int r = some_function(x);
asm(..使用结果的代码...:...:r(r),...
也就是说,你不想在内联asm中执行函数调用,这样你就不必担心调用约定的细节或者堆栈框架管理。
Say, I want to call a function with the following signature in inline assembly of gcc. How can I do that?
int some_function( void * arg );
解决方案
Generally you'll want to do something like
void *x;
asm(".. code that writes to register %0" : "=r"(x) : ...
int r = some_function(x);
asm(".. code that uses the result..." : ... : "r"(r), ...
That is, you don't want to do the function call in the inline asm at all. That way you don't have to worry about details of the calling conventions, or stack frame management.
这篇关于在gcc内联汇编中调用一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!