I am trying to mess around with my assembly function to get it to work but have ran into a couple of errors that are difficult to get by. One is A2005 which states symbol redefinition :_Average. The other one is A1010 which states unmatched block nesting :_Average Any help is appreciated.
.cpp code
#include<iostream>
using namespace std;
extern "C" long Average(long, long[]);
int main()
{
long Array1[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
long Array2[11] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
cout << "Average of Array1 is " << Average(10, Array1) << endl;
cout << "Average of Array2 is " << Average(11, Array2) << endl;
}
long Average(long, long[])
{
return 0;
}
.asm file
.386
.model flat
public _Average
.data
.code
_Average proc
push ebp;
mov edx, 10;
mov ebx, [ebp+12]
xor ecx, ecx;
xor eax, eax;
Loop1:
add eax, [edx + (ecx * 4)];
inc ecx;
cmp ecx, edx;
jnz Loop1;
Done1:
mov ebx, 2;
idiv ebx;
pop ebp;
ret
_Average endp
_Average proc
push ebp;
mov edx, 11;
mov ebx, [ebp+12];
xor ecx, ecx;
xor eax, eax;
Loop2:
add eax, [edx + (ecx * 4)];
inc ecx;
cmp ecx, edx;
jnz Loop2;
Done2:
mov ebx, 2;
idiv ebx;
pop ebp;
ret
_Average endp
end