ArrayNegateEx function

The ArrayNegateEx function converts each array element into its negative value. The pointer to the array and its length are passed through the stack. The function automatically aligns the stack to 4 bytes.

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

Return value: The function does not return a value.

Flag state: The function does not modify the flags.

Program source code

Intel 8086 assembly program example demonstrating the use of the ArrayNegateEx function to invert the sign of array elements.

title Author: Evgeny Sergeevich Dovgopolov

.286C
.model small
.stack 100h

data segment public
    array  dw 4, -1, -4, 3
    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    4                  ; 2nd: Push the length of the array array onto the top of the stack
        pushs   ds:[array]         ; 1st: Push the address of the array array onto the top of the stack
        call    ArrayNegateEx      ; Call the ArrayNegateEx(array, 4) procedure

        loopcnt 4                  ; Set the counter to 4. CX := 4
        leabx   ds:[array]         ; Load the address of the array array 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

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

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