The ArrayAbsolute function

The ArrayAbsolute function converts each array element to its absolute value.

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

Return value: The function does not return a value.

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 ArrayAbsolute function to convert array elements to their absolute values.

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

data segment public
    array  dw 4, -1, -4, 3
    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     bx, 4              ; Copy the value 4 into the bx register
        lea     ax, ds:[array]     ; Load the address of the variable array into the ds:ax register
        call    ArrayAbsolute      ; Call the ArrayAbsolute procedure (ds:ax, 4)

        mov     cx, 4              ; Copy the value 4 into the cx register
        lea     si, ds:[array]     ; Load the address of the variable array into the ds:si register

    PrintArrayLoop:
        push    word ptr[si]       ; 2nd: Save the si 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, si)
        add     sp, 2              ; Align the stack
        incw    si                 ; Call the incw macro. Increment si 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

[4] [1] [4] [3]

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