内联汇编程序调用子程序
我对内联汇编器有疑问。是否可以从同一函数内的内联汇编程序调用另一个汇编程序子例程?例如:
void FindValidPID(unsigned int &Pid)
{
__asm
{
sub esp, 20h
mov eax, Pid
add eax,eax
call sub123 ; another assm subroutine
mov Pid, eax
add esp, 20h
}
}
我应该在哪里以及如何编写子程序 sub123?
干杯,
托马斯
I have question about inline assembler. It's possible to call another assembler subroutine from inline assembler within the same function? For example:
void FindValidPID(unsigned int &Pid)
{
__asm
{
sub esp, 20h
mov eax, Pid
add eax,eax
call sub123 ; another assm subroutine
mov Pid, eax
add esp, 20h
}
}
Where I should, and how, write subroutine sub123?
Cheers,
Thomas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您正在汇编中编写整个子例程,则应该考虑使用文件级汇编器而不是内联。
If you are writing an entire subroutine in assembly, you should look into using the file-level assembler rather than inline.
假设你有一个用汇编语言编写的子程序
_func2
(我只知道NASM语法)。您可以像这样从 C++ 代码中调用此子例程。
当然,
func2
也可以是带有__asm
块的 C/C++ 函数。Suppose you have a subroutine
_func2
written in assembler (I only know NASM syntax).You can call this subroutine from your C++ code like this
Of course
func2
can also be a C/C++ function with an__asm
block.从语法来看,我假设使用的编译器是VC++?如果是这样,则为裸函数 (http://msdn. microsoft.com/en-us/library/5ekezyy2(VS.80).aspx) 应该让您定义一个可以从汇编语言代码轻松调用的函数。
(裸函数对于 C++ 也是可见的,因此您也可以从 C++ 调用它们,并且可能会得到错误的结果......所以您必须小心!)
From the syntax, I assume the compiler being used is VC++? If so, a naked function (http://msdn.microsoft.com/en-us/library/5ekezyy2(VS.80).aspx) should let you define a function that can be easily called from assembly language code.
(Naked functions are also visible to C++, so you can call them from C++ as well and potentially get the wrong results... so you just have to be careful!)
您可以像创建第一个函数一样创建另一个函数,然后使用其损坏的名称(例如
call __GLOBAL__I_sub123;
)来调用它。将其声明为
extern "C"
可能是一个好主意,以使事情变得更简单。在 gcc 中,您可以使用 gcc -S file.cpp 来查看函数的损坏名称。
You could do it by creating the other function just as you did with the 1st one and then call it with its mangled name like
call __GLOBAL__I_sub123;
.It might be a good idea to declare it as
extern "C"
to make things simpler.In gcc, you can use
gcc -S file.cpp
to see what is the funciton's mangled name.