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
hw9.zip 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 numbers_size. 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 64-bit
value in edx: eax (that is, edx forms the most significant 32 bits of the dividend, and eax is its least
significant 32 bits). The divsor may not be an immediate value (i.e. div 10 won't work), so you have
to load the divisor into a register. Note, as well, that div ebx will divide the 64-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 64-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 32-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 8-bit, so the highest possible expressible average is 255. You can assume
that the average is less than 256. You can also assume that the sum of the array is less than 232.
You can assemble and link your program with commands similar to those discussed above:
user@ubuntu: / intel $ nasm -f elf -gstabs avg. asm
user@ubuntu: /intel$ ld -o avg -m elf_i386 avg.o
If your program works, you'll be able to verify the correct average by examining its exit status, as
follows:
Consider the following incomplete Intel assembly

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 Programming Questions!