Source (1).asm

mail@pastecode.io avatar
unknown
assembly_x86
7 months ago
1.0 kB
2
Indexable
Never
TITLE HW3_111502563
INCLUDE Irvine32.inc

CountEach PROTO,
    pArray1: PTR SDWORD,
    target: SDWORD,
    arraySize: DWORD

CountMatches PROTO,
    pArray1: PTR SDWORD,
    pArray2: PTR SDWORD,
    arraySize: DWORD

.data
array1 SDWORD 10, 5, 4, -6, 2, 11, 12
array2 SDWORD 10, 5, 3, 1, 4, 2, -6

.code
main PROC

    invoke CountMatches, OFFSET array1, OFFSET array2, LENGTHOF array1

    exit
main ENDP

CountEach PROC USES ecx ebx esi,
    pArray: PTR SDWORD,
    target: SDWORD,
    arraySize: DWORD

    mov esi, pArray
    mov ecx , arraySize
L3:
    mov ebx, [esi]
    cmp target, ebx
    jne L4
    inc eax
L4:
    add esi, 4
    loop L3
    ret
CountEach ENDP

CountMatches PROC USES ecx esi edi edx,
    pArray1: PTR SDWORD,
    pArray2: PTR SDWORD,
    arraySize: DWORD

    mov eax, 0
    mov ecx, arraySize
    mov esi, pArray1  
L1:
    invoke CountEach, pArray2, [esi], arraySize
    add esi, 4
    loop L1
    ret
CountMatches ENDP

END main
Leave a Comment