nasm/yasm 参数,链接到 C++
我有一个关于 nasm 及其与 C++ 的链接的问题。我将一个小测试函数声明为
extern "C" void __cdecl myTest( byte i1, byte i2, int stride, int *width );
,我这样称呼它:
byte i1 = 1, i2 = 2;
int stride = 3, width = 4;
myTest( i1, i2, stride, &width );
该方法仅用于调试程序集并看看如何使用堆栈指针来获取参数。除此之外,指针参数值应设置为 7,以了解其工作原理。这是这样实现的:
global _myTest
_myTest:
mov eax, [esp+4] ; 1
mov ebx, [esp+8] ; 2
mov ecx, dword [esp+16] ; width
mov edx, dword [esp+12] ; stride
mov eax, dword [esp+16]
mov dword [eax], 7
ret
并通过 编译
yasm -f win32 -g cv8 -m x86 -o "$(IntDir)\$(InputName).obj" "$(InputPath)"
,然后链接到 c++ 应用程序。在调试模式下,一切正常。该函数被调用几次并按预期工作,而在发布模式下该函数只能工作一次,但后续的编程操作会失败。在我看来,堆栈/帧指针、近/远有问题,但我对这个主题很陌生,需要一些帮助。提前致谢! 一个。
I've got a question concerning nasm and its linkage to C++. I declare a litte test function as
extern "C" void __cdecl myTest( byte i1, byte i2, int stride, int *width );
and I call it like this:
byte i1 = 1, i2 = 2;
int stride = 3, width = 4;
myTest( i1, i2, stride, &width );
the method only serves to debug assembly and have a look at how the stack pointer is used to get the arguments. beyond that, the pointer arguments value shall be set to 7, to figure out how that works. This is implemented like this:
global _myTest
_myTest:
mov eax, [esp+4] ; 1
mov ebx, [esp+8] ; 2
mov ecx, dword [esp+16] ; width
mov edx, dword [esp+12] ; stride
mov eax, dword [esp+16]
mov dword [eax], 7
ret
and compiled via
yasm -f win32 -g cv8 -m x86 -o "$(IntDir)\$(InputName).obj" "$(InputPath)"
, then linked to the c++ app. In debug mode, everything works fine. the function is called a couple of times and works as expected, whereas in release mode the function works once, but subsequent programm operations fail. It seems to me that something's wrong with stack/frame pointers, near/far, but I'm quite new to this subject and need a little help. thanks in advance!
a.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,看来我必须通过push/pop 保存
ebx
。Well, it seems that I have to preserve
ebx
via push/pop.可能这会有所帮助: FLAC 在汇编器中使用了一些打算由 nasm 编译的源代码。
May be this helps: FLAC uses some sources in assembler which intended to be compiled by nasm.