ArrayMakeUnique 函数

ArrayMakeUnique 函数将第一个数组中的唯一元素复制到第二个数组。

参数: DS:AX:第一个数组(源)指针;ES:BX:第二个数组(目标)指针;CX:第一个数组的长度。

返回值: CX:复制到第二个数组中的唯一元素数量。

标志状态: 函数不改变标志状态。

程序源代码

Intel 8086 汇编程序示例,演示使用 ArrayMakeUnique 函数提取数组中的唯一元素。

title Author: Dovgopolov Evgeny Sergeevich

.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                ; 代码段开始
    assume  ds:data, cs:code
    include Handyfar.inc           ; 包含函数文件
    include Handymac.inc           ; 包含宏文件

    main proc                      ; main 过程开始
        call    SetDataSegment     ; 调用过程 SetDataSegment

        mov     cx, arrlen         ; 将数组 origin 的长度复制到寄存器 cx
        lea     bx, es:[unique]    ; 将变量 unique 的地址装入寄存器 es:bx
        lea     ax, ds:[origin]    ; 将变量 origin 的地址装入寄存器 ds:ax
        call    ArrayMakeUnique    ; 调用过程 ArrayMakeUnique(ds:ax, es:bx, cx) := CX

    PrintArrayLoop:
        push    word ptr[bx]       ; 第2步:将寄存器 bx(unique)的值保存到栈中
        lea     ax, ds:[fmtout]    ; 第1步:将格式字符串 fmtout 的地址装入寄存器 ds:ax
        call    PrintFormatString  ; 调用过程 PrintFormatString(ax:fmtout, bx)
        add     sp, 2              ; 对齐栈
        incw    bx                 ; 调用宏 incw。将索引 bx 增加 2
        loop    PrintArrayLoop     ; 当 CX≠0 时执行循环

        xor     al, al             ; 清零寄存器 al
        call    ExitProcess        ; 调用过程 ExitProcess
    main endp                      ; main 过程结束

code ends                          ; 代码段结束
end main	                       ; 文件结束。入口点指定为过程 main

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

示例取自教材 "HANDYFAR - MASM (Dovgopolov Evgeny Sergeevich)".