The ArrayCompare function
The ArrayCompare function compares two arrays element by element. If the arrays are equal, the function sets the zero flag (ZF = 1); otherwise it clears it (ZF = 0).
Parameters: DS:AX - pointer to the first array; ES:BX - pointer to the second array; CX - number of elements to compare.
Return value: ZF = 1 if the arrays are equal; ZF = 0 otherwise.
Flag state: The function affects all flags.
Program source code
An example program for the Intel 8086 assembler demonstrating the use of the ArrayCompare function to compare two arrays.
title .model small .stack 100h data segment public array1 dw 1234h, 2345h, 3456h, 4567h array2 dw 1234h, 2345h, 3454h, 4567h equal db "Arrays are equal!\0" notEqual db "Arrays are not equal!\0" data ends code segment public ; Start of the code segment assume ds:data, cs:code include Handyfar.inc ; Include the file with functions main proc ; Start of the main procedure call SetDataSegment ; Call the SetDataSegment procedure mov cx, 4 ; Copy the number 4 into the cx register lea bx, es:[array2] ; Load the address of the variable array2 into the es:bx register lea ax, ds:[array1] ; Load the address of the variable array1 into the ds:ax register call ArrayCompare ; Call the ArrayCompare procedure (ds:ax, es:bx, cx) := ZF jne ArraysNotEqual ; If ZF=0, jump to the ArraysNotEqual label lea ax, ds:[equal] ; Load the address of the variable equal into the ds:ax register jmp Done ; Perform an unconditional jump to the Done label ArraysNotEqual: lea ax, ds:[notEqual] ; Load the address of the variable notEqual into the ds:ax register Done: call WriteString ; Call the WriteString procedure (ax) xor al, al ; Clear the al register call ExitProcess ; Call the ExitProcess procedure main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
Arrays are not equal!
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".