The ArrayGetMaximum function

The ArrayGetMaximum function finds the maximum value in a given array of numbers.

Parameters: AX: pointer to the array; BX: array length.

Return value: AX: maximum value in the 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 ArrayGetMaximum function to find the maximum value in an array.

title Author: Evgeny Sergeevich Dovgopolov

.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 the array: %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

    main proc                      ; Start of the main procedure
        call    SetDataSegment     ; Call the SetDataSegment procedure

        mov     bx, arrlen         ; Copy the array length into the bx register
        lea     ax, ds:[array]     ; Load the address of the variable array into the ds:ax register
        call    ArrayGetMaximum    ; Call the ArrayGetMaximum procedure (ds:ax, bx) := AX

        push    ax                 ; 2nd: save the ax 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
        add     sp, 2              ; Align the stack

        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

Maximum number in the array: 67

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