ArrayConcatenateEx function
The ArrayConcatenateEx function copies the elements of the second array to the end of the first one. The parameters are passed through the stack. It returns the total number of elements in CX. The function automatically aligns the stack to 8 bytes.
Parameters (stack): 1. Pointer to the first array. 2. Pointer to the second array. 3. Size of the first array. 4. Size of the second array.
Return value: CX - the total number of elements in the first array after copying.
Flag state: The function does not modify the flags.
Program source code
Intel 8086 assembly program example demonstrating the use of the ArrayConcatenateEx function to concatenate two arrays.
title .286C .model small .stack 100h data segment public array1 dw 1, 2, 3, 4 arrlen1 equ ($-array1) / 2 dw 10 dup(0) ; Reserve 10 words so that array2 fits array2 dw 5, 6, 7, 8, 9 arrlen2 equ ($-array2) / 2 output db "Array: \0" 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 arrlen2 ; 4th: Push the length of the array array onto the top of the stack2 push arrlen1 ; 3rd: Push the length of the array array1 onto the top of the stack pushs es:[array2] ; 2nd: Push the address of the array array2 onto the top of the stack pushs ds:[array1] ; 1st: Push the address of the array array1 onto the top of the stack call ArrayConcatenateEx ; Call the ArrayConcatenateEx(arr1, arr2, 4, 5) procedure := CX pushs ds:[output] ; Push the address of the output variable onto the top of the stack call WriteStringEx ; Call the WriteStringEx(output) procedure leabx ds:[srray1] ; Load the address of the array array1 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
Array: [1] [2] [3] [4] [5] [6] [7] [8] [9]
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".