I have an assignment for my school I will paste the instructions down below, I am just wondering what I would have to do for the average assembly function, all 3 other functions are completed.
Write a C/C++ program that does the following:
in C++ program declare an array of integers (size is your choice)--your program should work with any array size call an assembly function to compute the average of all elements in the array (pass the array and the size of the array) call an assembly function to compute the largest (max) of all elements in the array (pass the array and the size of the array) call an assembly function to compute the smallest (min) of all elements in the array (pass the array and the size of the array) display the average, min, and max in C++ program There should be three assembly files for the three functions (average-40 points, largest-30points, smallest-30 points)
Below I will post my C++ code as well as the largest and smallest function
C++ code is below:
#include <iostream>
using namespace std;
int main()
{
int sz;
cout << "How many numbers do you want the array to generate?:";
cin >> sz;
int randArray[sz];
for (int i = 0; i < sz; i++)
randArray[i] = rand() % 1000;
cout << "\nnumbers in array:" << endl;
for (int i = 0; i < sz; i++)
cout << "number " << i + 1 << "::" << randArray[i] << endl;
return 0;
}
Assembly function for the largest is below:
.686
.model flat
.code
_max PROC; named _max because C automatically prepends an underscode, it is needed to interoperate
push ebp
mov ebp, esp; stack pointer to ebp
mov ebx, [ebp + 8]; address of first array element
mov ecx, [ebp + 12]
mov ebp, 0
mov edx, 0
mov eax, [ebx]
loopMe:
cmp ebp, ecx
je allDone
cmp eax, [ebx + edx]
jg continue
mov eax, [ebx + edx]
continue:
add edx, 4
add ebp, 1
jmp loopMe
allDone :
pop ebp
ret
_max ENDP
END
Assembly function for the smallest is below:
.model flat
.code
_smallest PROC
push ebp
mov ebp,esp ;stack pointer to ebp
mov ebx,[ebp+8] ; address of first array element
mov ecx,[ebp+12]
mov ebp,0
mov edx,0
mov eax,[ebx]
loopMe:
cmp ebp,ecx
je allDone
cmp eax,[ebx+edx]
jl continue
mov eax,[ebx+edx]
continue:
add edx,4
add ebp,1
jmp loopMe
allDone:
pop ebp
ret
_smallest ENDP
END
The only difference between the smallest and largest function is that the smallest function has "jl"=jump less under loopMe and the largest function has "jg"=jump greater under loopMe. What would I have to change in this function to make it solve for average? I was told by the professor that I only needed to change two things for that function specifically. If anyone is able to point out what I am missing I would greatly appreciate it!