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

Write a procedure named CountNearMatches that receives pointers to two arrays of

ID: 3715847 • Letter: W

Question

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 xi in the ?rst array, if the difference between it and the corresponding yi in the second array is less than or equal to diff, increment a count. At the end, return a count of the number of nearly matching array elements in EAX. Write a test program that calls CountNearMatches and passes pointers to two different pairs of arrays. Use the INVOKE statement to call your procedure and pass stack parameters. Create a PROTO declaration for CountMatches. Save and restore any registers (other than EAX) changed by your procedure.

Explanation / Answer

INCLUDE Irvine32.inc
CountNearMatches 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 CountNearMatches, ADDR First_Arr, ADDR First_Arr1, LENGTHOFFirst_Arr, difference1
             call WriteInt
             call Crlf
             INVOKE CountNearMatches, 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
     CountNearMatches 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
     CountNearMatches 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