Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Comparisons Write a program that contains the following array and the following

ID: 3622607 • Letter: C

Question

Comparisons

Write a program that contains the following array and the following PROCs:

array1: 14,70,50,40,80,85,72,88,25,60,74,90,94,79,81,63,97,78,65,82,74,69,70,75,45

MAIN: This should simply set up appropriate registers with the information needed by the other PROCs and then call them as needed to produce the results. After value-returning PROCs are called, MAIN should store the values in appropriately named memory locations. Don't assume that array1 will have a fixed number of elements; that is, don't assume that the array has 25 elements -- your program should work properly if you simply go in and edit array1 to have different elements or a different number of elements.

LARGE: This PROC should be passed the location of the array and the number of elements in the array in appropriate registers, and it should return the largest value in the array in the EAX register.

SMALL: Same as LARGE, but the value returned should be the smallest value in the array.

SUM: Same as LARGE, but the value returned should be the sum of the elements in the array.

DISPL: This procedure should be passed, in a register, the location of the first of the three numbers produced by the latter three procedures and it should display all three results, with appropriate labels. Note: This requires the largest, smallest and sum to be stored in contiguous data locations.

Make sure the program and all procedures (except MAIN -- it's documentation is the program documentation) have appropriate documentation at the beginning, as well as line by line to explain what is going on.

Explanation / Answer

.data array1 DWORD 14,70,50,40,80,85,72,88,25,60,74,90,94,79,81,63,97,78,65,82,74,69,70,75,45 largeString BYTE "Largest Number in the array: ",0 smallString BYTE "Smallest Number in the array: ",0 totalString BYTE "The sum of all Numbers in the array: ",0 largest DWORD ? smallest DWORD ? total DWORD ? .code main PROC MOV ecx, LENGTHOF array1 MOV esi, 0 CALL LARGE ; LARGE returns the largest number in eax MOV largest, eax MOV ecx, LENGTHOF array1 MOV esi, 0 CALL SMALL ; SMALL returns the smallest number in eax MOV smallest, eax MOV ecx, LENGTHOF array1 MOV esi, 0 CALL SUM ; SUM returns the sum of all numbers in eax MOV total, eax MOV eax, largest MOV ebx, smallest MOV ecx, total CALL DISPL ; prints out the result passed by eax,ebx,ecx exit main ENDP LARGE PROC mov eax, array1[esi] ; Get the first number in the array add esi, TYPE array1 ; Get the index of the next number dec ecx ; decrement the counter L1: CMP array1[esi],eax ; Compare the current number with the smallest value found jng NotLarge ; Jump in not greater than mov eax, array1[esi] ; This line is skipped if jumped NotLarge: add esi, TYPE array1 ; Get the index of the next number loop L1 ret LARGE ENDP SMALL PROC mov eax, array1[esi] ; Get the first number in the array add esi, TYPE array1 ; Get the index of the next number dec ecx ; decrement the counter L1: CMP array1[esi],eax ; Compare the current number with the smallest value found jnl NotSmall ; Jump in not less than mov eax, array1[esi] ; This line is skipped if jumped NotSmall: add esi, TYPE array1 ; Get the index of the next number loop L1 ret SMALL ENDP SUM PROC mov eax, 0 L1: add eax, array1[esi] ; Add the current number to eax add esi, TYPE array1 ; Get the index of the next number loop L1 ret SUM ENDP DISPL PROC mov edx, OFFSET largeString call WriteString call WriteDec call crlf mov edx, OFFSET smallString call WriteString mov eax,ebx call WriteDec call crlf mov edx, OFFSET totalString call WriteString mov eax,ecx call WriteDec call crlf call crlf call WaitMsg ret DISPL ENDP END main

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote