ArrayMakeUniqueEx function

The ArrayMakeUniqueEx function copies the unique elements from the source array into the destination array. The parameters are passed through the stack. It returns the number of unique elements in CX. The function automatically aligns the stack to 6 bytes.

Parameters (stack): 1. Pointer to the source array. 2. Pointer to the destination array. 3. Length of the source array.

Return value: CX - the number of unique elements.

Flag state: The function does not modify the flags.

Program source code

Intel 8086 assembly program example demonstrating the use of the ArrayMakeUniqueEx function to extract the unique elements of an array.

title Author: Evgeny Sergeevich Dovgopolov

.286C
.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  255 dup(0)
    fmtout db  "[%d] \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    arrlen             ; 3rd: Push the length of the array onto the top of the stack
        pushs   es:[unique]        ; 2nd: Push the length of the array unique onto the top of the stack
        pushs   ds:[origin]        ; 1st: Push the address of the array origin onto the top of the stack
        call    ArrayMakeUniqueEx  ; Call the ArrayMakeUniqueEx(origin, unique, 12) procedure := CX

        leabx   ds:[unique]        ; Load the address of the array unique into the ds:bx register
        xor     si, si             ; Clear the index register

    PrintArrayLoop:
        push    word ptr[bx+si]    ; 2nd: Push the value in bx at index si onto the top of the stack
        leaax   ds:[fmtout]        ; 1st: Load the address of the fmtout format string into the ds:ax register
        call    PrintFormatString  ; Call the PrintFormatString(ax:fmtout, bx) procedure
        add     sp, 2              ; Align the stack
        incw    si                 ; Increase the index si by 2
        loop    PrintArrayLoop     ; Loop while the cx register is not equal to 0

        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

[7] [5] [8] [3] [6] [1] [9]

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