Question: Consider the following incomplete Intel assembly language program, avg asm, which is provided in the hw 9 . zip file: Complete the program so that
Consider the following incomplete Intel assembly language program, avg asm, which is provided in the
hwzip file:
Complete the program so that it calculates the integer average of values of the unsigned dword array
numbers. The length of the array is stored at address numberssize. Your program should work
correctly with an array containing any content, of any nonzero length. The suggested approach is to
first sum the array, then divide. The final result should be returned as the exit status from the exit
syscall.
Please examine the documentation for the div instruction. This instruction is slightly anomalous.
Notice that div takes only one argument, the divisor, while the dividend is always implicitly the bit
value in edx: eax that is edx forms the most significant bits of the dividend, and eax is its least
significant bits The divsor may not be an immediate value ie div won't work so you have
to load the divisor into a register. Note, as well, that div ebx will divide the bit value in edx : eax
by ebx, and will store the quotient in eax and the remainder in edx. A consequence of the fact that div
divides a bit value, whose high dword is in edx and whose low dword is in eax, is that, if you want
to divide only eax you must ensure that edx is zero before you issue the instruction. Furthermore, the
quotient must fit in the bit register eax: in case of quotient overflow, the CPU will signal a divide
error, and your program will terminate.
Use the Linux exit syscall to terminate your program normally. Specify the array's average value as
the exit status in ebx, as follows:
Note that the exit value is bit, so the highest possible expressible average is You can assume
that the average is less than You can also assume that the sum of the array is less than
You can assemble and link your program with commands similar to those discussed above:
user@ubuntu: intel $ nasm elf gstabs avg. asm
user@ubuntu: intel$ ld o avg m elfi avg.o
If your program works, you'll be able to verify the correct average by examining its exit status, as
follows:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
