由于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;
}
答案 0 :(得分:4)
保持一个正在运行的总数而不是全部加载它们然后全部添加它们。
答案 1 :(得分:3)
首先无需加载然后添加,您可以这样做:
fld real8 ptr [ebx]
fadd real8 ptr [ebx + 8]
fadd real8 ptr [ebx + 16]
fadd real8 ptr [ebx + 24]
依旧......