The ArrayCopy function

The ArrayCopy function copies elements from the first array to the second array.

Parameters: DS:AX - pointer to the first array (source); ES:BX - pointer to the second array (destination); CX - number of elements to copy.

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 ArrayCopy function to copy an array.

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

data segment public
    array1 dw  1234h, 2345h, 3456h, 4567h
    arrlen equ ($-array1) / 2
    array2 dw  arrlen dup(?)
    output db  "Copied array: \0"
    fmtout db  "[%h] \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     cx, arrlen         ; Copy the array length into the cx register
        lea     bx, es:[array2]    ; Load the address of the variable array2 into the es:bx register
        lea     ax, ds:[array1]    ; Load the address of the variable array1 into the ds:ax register
        call    ArrayCopy          ; Call the ArrayCopy procedure (ds:ax, es:bx, cx)

        lea     ax, ds:[output]    ; Load the address of the variable output into the ds:ax register
        call    WriteString        ; Call the WriteString procedure (ax)

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

Copied array: [1234] [2345] [3456] [4567]

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