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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!