我正在尝试将C和NASM接口传递一个float数组,进行几步(对数组的每个元素减去2.0),然后将数组结果的总和返回给C.打印的错误结果是x = -34975412102996426752.000000
我不明白为什么.. 感谢帮助 这是文件代码(test.c和myfunc.nasm):
test.c的:
extern float myfunc(float* a);
int main(int argc, char** argv) {
float a[] = { 7.0, 24.0, 4.0, 6.1 };
float x = myfunc(a);
printf("x: %f\n",x);
return 0;
}
myfunc.nasm:
%include "sseutils.nasm"
section .data
align 16
y: dd 2.0 , 2.0, 2.0, 2.0
section .bss
alignb 16
A: resd 4
section .text
global myfunc
a equ 8
myfunc:
push ebp
mov ebp, esp
push ebx
movaps xmm0 , [ebp+a]
movaps xmm1,[y]
subps xmm0, xmm1
haddpd xmm0,xmm0
haddpd xmm0,xmm0
movaps [A], xmm0
fld dword[A]
pop ebx
mov esp, ebp
pop ebp
ret