将数组传递给 x86 asm 中的函数
我正在学习 x86 asm 并使用 masm,并且正在尝试编写一个与以下 c 函数具有等效签名的函数:
void func(double a[], double b[], double c[], int len);
我不确定如何实现它?
asm 文件将被编译成 win32 DLL。
为了让我明白如何做到这一点,有人可以帮我将这个非常简单的函数翻译成asm吗:
void func(double a[], double b[], double c[], int len)
{
// a, b, and c have the same length, given by len
for (int i = 0; i < length; i++)
c[i] = a[i] + b[i];
}
我尝试用C编写一个这样的函数,编译它,并使用OllyDbg查看exe中相应的反汇编代码,但是我甚至在其中找不到我的功能。
谢谢您。
I'm learning x86 asm and using masm, and am trying to write a function which has the equivalent signature to the following c function:
void func(double a[], double b[], double c[], int len);
I'm not sure how to implement it?
The asm file will be compiled into a win32 DLL.
So that I can understand how to do this, can someone please translate this very simple function into asm for me:
void func(double a[], double b[], double c[], int len)
{
// a, b, and c have the same length, given by len
for (int i = 0; i < length; i++)
c[i] = a[i] + b[i];
}
I tried writing a function like this in C, compiling it, and looking at the corresponding disassembled code in the exe using OllyDbg but I couldn't even find my function in it.
Thank you kindly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经有一段时间没有写 x86 了,但我可以给你一个如何写 x86 的一般概念。由于我手边没有汇编程序,所以这是用记事本编写的。
上面的函数符合 stdcall,如果您的参数是整数,则大致是您将如何转换为 x86。不幸的是,您正在使用双打。循环是相同的,但您需要使用 FPU 堆栈和操作码来进行算术运算。我已经有一段时间没有使用它了,不幸的是我记不起这些说明了。
I haven't written x86 for a while but I can give you a general idea of how to do it. Since I don't have an assembler handy, this is written in notepad.
The above function conforms to stdcall and is approximately how you would translate to x86 if your arguments were integers. Unfortunately, you are using doubles. The loop would be the same but you'd need to use the FPU stack and opcodes for doing the arithmetic. I haven't used that for a while and couldn't remember the instructions off the top of my head unfortunately.
您必须传递数组的内存地址。考虑以下代码:
我编写这段代码只是为了让您理解这个概念。我将它留给您来弄清楚如何正确计算寄存器的使用以实现程序的目标。
You have to pass the memory addresses of the arrays. Consider the following code:
I just wrote this code for you to understand the concept. I leave it to you to figure out how to properly figure the usage of registers in order to achieve your program's goals.