ArrayCompareEx function

The ArrayCompareEx function compares two arrays element by element. The pointers to the arrays and the number of elements are passed through the stack. The function automatically aligns the stack to 6 bytes.

Parameters (stack): 1. Pointer to the first array. 2. Pointer to the second array. 3. Number of elements.

Return value: ZF = 1 if the arrays are equal; ZF = 0 if they are not equal.

Flag state: The function affects all flags.

Program source code

Intel 8086 assembly program example demonstrating the use of the ArrayCompareEx function for element-by-element comparison of two arrays.

title Author: Evgeny Sergeevich Dovgopolov

.286C
.model small
.stack 100h

data segment public
    array1   dw 23, 54, 83, 91
    array2   dw 23, 54, 41, 91
    equal    db "The arrays are equal!\0"
    notEqual db "The arrays are not equal!\0"
data ends

code segment public
    assume  ds:data, cs:code
    include Handyfar.inc         ; Include the file with functions
    include Handymac.inc         ; Include the file with macros

    main proc
        call    SetDataSegment   ; Call the SetDataSegment procedure

        push    4                ; 3rd: Push the length of the array onto the top of the stack
        pushs   es:[array2]      ; 2nd: Push the address of the array array2 onto the top of the stack
        pushs   ds:[array1]      ; 1st: Push the address of the array array1 onto the top of the stack
        call    ArrayCompareEx   ; Call the ArrayCompareEx(array1, array2, 4) procedure := ZF

        jne     @ArraysNotEqual  ; If ZF=0, jump to the label @ArraysNotEqual

        pushs   ds:[equal]       ; Push the address of the equal variable onto the top of the stack
        jmp     @Done            ; Perform an unconditional jump to the label @Done

    @ArraysNotEqual:
        pushs   ds:[notEqual]    ; Push the address of the notEqual variable onto the top of the stack

    @Done:
        call    WriteStringEx    ; Call the WriteStringEx procedure (value from the stack)

        push    0                ; Push the byte return code onto the top of the stack
        call    ExitProcessEx    ; Call the ExitProcessEx(0) procedure
    main endp

code ends
end main

The arrays are not equal!

Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".