Question
Starting with the following C++ program: #include using namespace std; extern C long Average ( long, long[]); void main () { long Array1[10] = {1,
Starting with the following C++ program:
#include
using namespace std;
extern C long Average ( long, long[]);
void 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;
}
Write in assembly language (in a separate file named Lab8.asm) the functionAverage.
The first parameter is the number of elements in an array, the second is the address of the array.
The function will determine the average of the values in the array and return the average rounded to the nearest whole number (if the fractional part of the result is equal to or greater than .5, the result is rounded to the next higher number.
--------------------------------------------------------------------------------------
This is what I have found, however i do not believe the method of finding and rounding up the average is accurate.
|Average.asm|
.386
.model flat
public _Average
extern _CAverage:proc
.data
.code
_Average proc
push ebp
mov ebp, esp
sub esp, 4
mov eax, [ebp+4]
mov ebx, [ebp+12]
mov edx, 0
Loop1:
cmp ebx, 0
je Done1
add edx, ebx
add ebx, 8
jmp Loop1
Done1:
div edx, eax
srp edx, 6, 5
mov esp, ebp
pop ebp
ret
_Average endp
end
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started