gpt4 book ai didi

assembly - 添加 float 组

转载 作者:行者123 更新时间:2023-12-02 07:50:36 24 4
gpt4 key购买 nike

既然 FPU Stack 只有 8 个槽位,我该如何添加更多的元素。我有一个包含 10 个元素的数组需要添加。这是我目前所拥有的

_Average proc

finit

mov ecx, [esp + 4] ; get the number of elements
mov ebx, [esp + 8] ; get the address of the array

fld REAL8 PTR [ebx] ; get first element of array
fld REAL8 PTR [ebx + 8] ; get second element of array
fld REAL8 PTR [ebx + 16]; this element is now at the top of the stack
fld REAL8 PTR [ebx + 24]
fld REAL8 PTR [ebx + 32]
fld REAL8 PTR [ebx + 40]
fld REAL8 PTR [ebx + 48]
fld REAL8 PTR [ebx + 56]
;fld REAL8 PTR [ebx + 64]
;fld REAL8 PTR [ebx + 72]

fadd
fadd
fadd
fadd
fadd
fadd
fadd
;fadd
;fadd
fwait ; if necessary wait for the co-processor to finish
ret
_Average endp

extern "C" double Average (int, double []);

void main ()
{
double Array1 [10] = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.0};

double Array2 [11] = {-1.1, -2.2, -3.3, -4.4, -5.5, -6.6, -7.7, -8.8, -9.9, -10.0, -11.0};

cout << "Average of Array1 is " << Average (10, Array1) << endl;

cout << "Average of Array2 is " << Average (11, Array2) << endl;

}

最佳答案

保持运行总计而不是全部加载然后将它们全部相加。

关于assembly - 添加 float 组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4074613/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com