ArrayGetMaximumEx 函数

ArrayGetMaximumEx 函数在数组中查找最大值。数组指针及其长度通过栈传递。函数会自动将栈对齐 4 个字节。

参数(栈): 1. 数组指针。2. 数组长度。

返回值: AX — 最大值。

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

程序源代码

Intel 8086 汇编程序示例,演示使用 ArrayGetMaximumEx 函数在数组中查找最大值。

title Author: Dovgopolov Evgeny Sergeevich

.286C
.model small
.stack 100h

data segment public
    array  dw  4, 7, 3, 67, 5, 22, 5, 66, 8, 5
    arrlen equ ($-array) / 2
    fmtout db  "Maximum number in array: %d\0"
data ends

code segment public
    assume  ds:data, cs:code
    include Handyfar.inc           ; 包含函数文件
    include Handymac.inc           ; 包含宏文件

    main proc
        call    SetDataSegment     ; 调用过程 SetDataSegment

        push    arrlen             ; 第2步:将数组 array 的长度压入栈顶
        pushs   ds:[array]         ; 第1步:将数组 array 的地址压入栈顶
        call    ArrayGetMaximumEx  ; 调用过程 ArrayGetMaximumEx(array, arrlen) := AX

        push    ax                 ; 第2步:将寄存器 ax 的值压入栈顶
        leaax   ds:[fmtout]        ; 第1步:将格式字符串 fmtout 的地址装入寄存器 ds:ax
        call    PrintFormatString  ; 调用过程 PrintFormatString(ax:fmtout, ax)
        add     sp, 2              ; 对齐栈

        push    0                  ; 将字节值(返回代码)压入栈顶
        call    ExitProcessEx      ; 调用过程 ExitProcessEx(0)
    main endp

code ends
end main

Maximum number in array: 67

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