我有一个外部功能:
extern "C" void calculateAreaUnderCurve_(double startPoint, double endPoint, int numberOfTrapezes, double* coefficients, double* result);
我想将numberOfTrapezes
转换为.asm文件中的double
。
我尝试过:vcvtsi2sd
和cvtsi2sd
,但它不起作用。
编辑:
这是我的.asm文件
.model flat,c
.code
; Function declatation:
; int calculateAreaUnderCurve_(double startPoint, double endPoint,
; int numberOfTrapezes, double* coefficients, double* result);
calculateAreaUnderCurve_ proc
push ebp
mov ebp,esp
; Load argument values
vmovsd xmm1,real8 ptr [ebp+8] ;xmm1 = startPoint
vmovsd xmm2,real8 ptr [ebp+16] ;xmm2 = endPoint
mov ebx, [ebp+20] ;ebx = numberOfTrapezez int value
mov eax, [ebp+28] ;eax = pointer to coefficients array
mov ecx, [ebp+32] ;ecx = pointer to result
cvtsi2sd xmm3,dword [ebp+20] ;convert to double
movsd real8 ptr [ecx],xmm3 ;save result
pop ebp
ret
calculateAreaUnderCurve_ endp
end
我的函数调用:
int numberOfTrapezes=100;
//initialize other parameters
calculateAreaUnderCurve_(startPoint,endPoint,numberOfTrapezes, coefficients, &result);
结果我得到了奇怪的号码1.0761e+09
答案 0 :(得分:6)
vmovsd xmm1,real8 ptr [ebp+8] ;xmm1 = startPoint vmovsd xmm2,real8 ptr [ebp+16] ;xmm2 = endPoint mov ebx, [ebp+20] ;ebx = numberOfTrapezez int value
您正在从错误的地址检索 numberOfTrapezez ! endPoint 占用8个字节,因此将偏移量从20更改为24。
mov ebx, [ebp+24]
以及
cvtsi2sd xmm3,dword [ebp+24] ;convert to double