Create a procedure named FindLargest that receives two parameters: a pointer to
ID: 3574752 • Letter: C
Question
Create a procedure named FindLargest that receives two parameters: a pointer to a signed doubleword array, and a count of the array's length. The procedure must return the value of the largest array member in EAX. Use the PROC directive with a parameter list when declaring the procedure. Preserve all registers (except EAX) that are modified by the procedure. Write a test program that calls FindLargest and passes three different arrays of different lengths. Be sure to include negative values in your arrays. Create a PROTO declaration for FindLargest.
Explanation / Answer
I have written a PROTO declaration for the code. The idea is to scan through each of the elements in the array and then compare the existing array member with the highest array value. Store the temp highest in the EAX register. Keep on looping untill the end of the array.
.code
FindLargest PROC,
array_num: PTR DWORD,
arraySize: DWORD
mov esi, array_num
mov ecx, arraySize
mov eax, [esi]
dec ecx
scan_array:
add esi, 4
mov ebx, [esi]
cmp ebx, eax
JLE check_number
mov eax, ebx
check_number:
loop scan_array
ret
FindLargest ENDP
END
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.