The ArrayMakeUnique function
The ArrayMakeUnique function copies unique elements from the first array to the second array.
Parameters: DS:AX - pointer to the first array (source); ES:BX - pointer to the second array (destination); CX - length of the first array.
Return value: CX - number of unique elements copied into the second array.
Flag state: The function does not modify the flags.
Program source code
An example program for the Intel 8086 assembler demonstrating the use of the ArrayMakeUnique function to extract the unique elements of an array.
title .model small .stack 100h data segment public origin dw 7, 5, 8, 3, 7, 5, 6, 3, 8, 1, 9, 5 arrlen equ ($-origin) / 2 unique dw arrlen dup(0) fmtout db "[%d] \0" data ends code segment public ; Start of the code segment assume ds:data, cs:code include Handyfar.inc ; Include the file with functions include Handymac.inc ; Include the file with macros main proc ; Start of the main procedure call SetDataSegment ; Call the SetDataSegment procedure mov cx, arrlen ; Copy the length of the origin array into the cx register lea bx, es:[unique] ; Load the address of the variable unique into the es:bx register lea ax, ds:[origin] ; Load the address of the variable origin into the ds:ax register call ArrayMakeUnique ; Call the ArrayMakeUnique procedure (ds:ax, es:bx, cx) := CX PrintArrayLoop: push word ptr[bx] ; 2nd: Save the bx (unique) register value on the stack lea ax, ds:[fmtout] ; 1st: Load the address of the fmtout format string into the ds:ax register call PrintFormatString ; Call the PrintFormatString procedure (ax:fmtout, bx) add sp, 2 ; Align the stack incw bx ; Call the incw macro. Increment the bx index by 2 loop PrintArrayLoop ; Loop while CX≠0 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
[7] [5] [8] [3] [6] [1] [9]
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".