The ArrayConcatenate function
The ArrayConcatenate function copies the elements of the second array to the end of the first array.
Parameters: DS:AX - pointer to the first array; ES:BX - pointer to the second array; CX - size of the first array; DX - size of the second array.
Return value: CX - total number of elements in the first array after copying.
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 ArrayConcatenate function to concatenate two arrays.
title .model small .stack 100h data segment public array1 dw 1111h, 2222h, 3333h, 4444h arrlen1 equ ($-array1) / 2 dw 10 dup(0) ; Add 10 words to make room for array2 array2 dw 5555h, 6666h, 7777h, 8888h, 9999h arrlen2 equ ($-array2) / 2 output db "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 dx, arrlen2 ; Copy the value of the arrlen2 variable into the dx register mov cx, arrlen1 ; Copy the value of the arrlen1 variable 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 ArrayConcatenate ; Call the ArrayConcatenate procedure (ds:ax, es:bx, cx, dx) := CX lea ax, ds:[output] ; Load the address of the variable output into the ds:ax register call WriteString ; Call the WriteString procedure (ax:output) 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 the si 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
Array: [1111] [2222] [3333] [4444] [5555] [6666] [7777] [8888] [9999]
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".