Question

Code written in NASM Function called findLargest Write a function called findLargest that receives two parameters:...

Code written in NASM

Function called findLargest
Write a function called findLargest that receives two parameters: an unsigned doubleword array and the length of the array. The function must return the value of the largest array member in eax. Preserve all registers (except eax) that are modified by the function. Write a test program in main that calls findLargest three times, each call using a different array with different lengths.

Function called countHits
Write a function called named countHits that takes as parameters two arrays of unsigned doublewords, and a third parameter that indicates the length of the two arrays (they are the same length). For each element in the first array, x(i), if the corresponding element in the second array, y(i) is equal, increment a count. After comparing the arrays, return a count of the number of matching array elements in registers eax. Write a test program in main that calls your function and passes the memory addresses of the arrays and the length of the arrays. Be sure to save and restore any registers, other than eax, that are changed by your procedure.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code For Function called findLargest:

INCLUDE Irvine32.inc

.data

numberrange DWORD 50, 100, -4, -5, 2, 5, 101, 34, 23, 45

numberrange1 DWORD 20, 30, 40, 50

numberrange2 DWORD - 2, -5, 2, 7, 3, 10, 15, 20, 5, 6, 21, 0, 4, -5, 31, 33

largernum DWORD 0

.code

Findlargest Proto, num:DWORD, num1 : DWORD, num2 : DWORD

main PROC

invoke FindLargest, ADDR numberrange, LENGTHOF numberrange, SIZEOF numberrange

invoke FindLargest, ADDR numberrange1, LENGTHOF numberrange1, SIZEOF numberrange1

invoke FindLargest, ADDR numberrange2, LENGTHOF numberrange2, SIZEOF numberrange2

exit

main ENDP

LargestMember PROC

mov largernum, [esi]

mov eax, [esi+4]

L1:

.if largernum < [esi]

mov largernum, [esi]

.endif

add esi, 4

inc ecx

loop l1

ret

LargestMember ENDP

END MAIN

Code for countHits:

INCLUDE Irvine32.inc
countHits PROTO, Pointer_Arr1:PTR SDWORD, Pointer_Arr2:PTR SDWORD, Arr_Size:DWORD, d:DWORD


.data
First_Arr SDWORD 1,2,3,4,5
First_Arr1 SDWORD 6,7,8,9,10
Second_Arr SDWORD 11,12,13,14,15
Second_Arr1 SDWORD 16,17,18,19,20
count DWORD ?,0
difference1 DWORD 11
difference2 DWORD 0
  
.code
main PROC   
INVOKE countHits, ADDR First_Arr, ADDR First_Arr1, LENGTHOFFirst_Arr, difference1
call WriteInt
call Crlf
INVOKE countHits, ADDR Second_Arr, ADDR Second_Arr1, LENGTHOFSecond_Arr, difference2
call WriteInt ;Library Function to display a message in Irvine32
call Crlf ;Library Function
exit
main ENDP

countHits PROC USES edx ebx edi esi ecx, Pointer_Arr1:PTR SDWORD, Pointer_Arr2:PTR SDWORD, Arr_Size:DWORD, d:DWORD
mov esi,Pointer_Arr1 ;copy the address of source address in extended source index register.
mov edi,Pointer_Arr2 ;copy the destination address in extended destination index register.
mov ecx,Arr_Size; the size of the array is copied into the c register.
Lable1: mov ebx,0 ;zero is stored in the b register.
mov ebx,[esi] ;The content of source index register is stored in b register.
mov edx,0;zero is stored in the d register.
mov edx,[edi];The content of source index register is stored in b register.
IF ebx > edx; compare the content of b and d register.
mov eax,ebx;if the content of b register is greater than d register, store the content of b register into a register.
sub eax,edx ; Subtract the content of d register from a register, the result is stored in a register.
ELSE
mov eax,edx; if the content of b register is smaller than d register, store the content of d register into a register.
sub eax,ebx ; Subtract the content of b register from a register, the result is stored in a register.
ENDIF
IF (eax <= d);If the content of a register is greater or equal to difference
inc count; Increment the counter
ENDIF
add esi, SIZEOF SDWORD ;Add the content of SIZEOF SDWORD to source index register.
add edi, SIZEOF SDWORD;Add the content of SIZEOF SDWORD to destination index register.
loop Lable1;Go to loop Lable1
mov eax,0; zero is stored in the a register.
mov eax,count;the content of count is stored in a register.
mov count,0; zero is stored in the count register.
ret
countHits ENDP
END main

Code attached for both the function .Please let me know for clarifications .

Add a comment
Know the answer?
Add Answer to:
Code written in NASM Function called findLargest Write a function called findLargest that receives two parameters:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assembly Language Program Help Write a procedure named CountNearMatches that receives pointers to two arrays of...

    Assembly Language Program Help Write a procedure named CountNearMatches that receives pointers to two arrays of signed doublewords, a parameter that indicates the length of the two arrays, and a parameter that indicates the maximum allowed difference (called diff) between any two matching elements. For each element x(i) in the first array, if the difference between it and the corresponding y(i) in the second array is less than or equal to diff, increment a count. At the end, return a...

  • Define an ordinary function called DisplayMin that has three parameters: the first two parameters are parallel...

    Define an ordinary function called DisplayMin that has three parameters: the first two parameters are parallel arrays of different types and the third argument is of type size_t representing the size of both arrays. The function DisplayMin must work when called with various types of actual arguments, for example string DisplayMin(string names[], int calories[], int size) or int DisplayMin(int calories[], float prices[], int size). (Parallel Arrays are two arrays whose data is related by a common index. For example: with...

  • 1. Write code for a function that receives two parameters (a,and b) by value and two...

    1. Write code for a function that receives two parameters (a,and b) by value and two more parameters (c and d) by reference. All parameters are double. The function works by assigning c to (a/b) and assigning d to (a*b). The function has no return value. From main, use scanf to get two numbers, then call the function, and then display both outcome values to the output in a printf statement. 2. After part 1 is completed, write code to...

  • this is assembly language for x-86 processors using microsoft visual studio Create a procedure named FindThrees...

    this is assembly language for x-86 processors using microsoft visual studio Create a procedure named FindThrees that returns 1 if an array has three consecutive values of 3 somewhere in the array. Otherwise, return 0. The procedure’s input parameter list contains a pointer to the array and the array’s size. 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 FindThrees...

  • Write this code using x86 assembly language using the irvine32 library

    Write this code using x86 assembly language using the irvine32 library Create a procedure that fills an array of doublewords with N random integers, making sure the values fall within the range j...k, inclusive. When calling the procedure, pass a pointer to the array that will hold the data, pass N, and pass the values of j and k. Preserve all register values between calls to the procedure. Write a test program that calls the procedure twice, using different values...

  • Write a function template named summarray, with two parameters: and array called are and an int...

    Write a function template named summarray, with two parameters: and array called are and an int holding the number of elements in arr. The function should return the sum of the elements in arr. this template must work for double or int arrays. Show a sample function call to the template function you wrote. What would you have to do to use the templates sumArray function with an array of objects of a custom class?   

  • 1. All functions should be written AFTER the main procedure. 2. A function prototype should be...

    1. All functions should be written AFTER the main procedure. 2. A function prototype should be written for each function and placed BEFORE the main procedure. 3. Each function should have a comment explaining what it does. 4. Each function parameter should have a comment explaining the parameter. 5. Prompt for the number of elements of the list. 6. Allocate an array whose size equals the number of elements specified by the user. 7. Read into the array the elements...

  • Write a C program (not C++) that calls a function to multiply a matrix (two dimensional...

    Write a C program (not C++) that calls a function to multiply a matrix (two dimensional array). The main program should ask the user to enter an integer that will be used as the matrix “adder” and then call the function. The function should perform a matrix increment (every element of the array is incremented by the same value) and assign the result to another array. The function should be flexible enough to work with any array size and “adder”,...

  • Write a C++ program that contains a function called swapNums. This function takes two integer parameters,...

    Write a C++ program that contains a function called swapNums. This function takes two integer parameters, swaps them in memory, and outputs the results (there is nothing to return). In main, ask the user to enter two different numbers, output them as entered (step 1), call the function swapNums() which will output the numbers swapped (step 2), and then output the values again in main (step 3). You should have three sets of output. Sample run (10 and 5 were...

  • Write a C++ function, smallestIndex, that takes as parameters an int array and its size and...

    Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occurrence of the smallest element in the array. To test your function, write a main that prompts a user for a list of 15 integers and outputs the index and value of the first occurrence of the smallest value. The program should print out Enter 15 integers: The position of the first occurrence of the smallest element in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT