Copying array elements into another array

In the following program example we will copy the elements of an array into another array.

Program source code

; Author: Evgeny Sergeevich Dovgopolov

src: db 0Ah, 09h, 08h, 07h, 06h, 05h, 04h, 03h, 02h, 01h
dst: db 00h, 00h, 00h, 00h, 00h, 00h, 00h, 00h, 00h, 00h

main:
    lxi     h, src    ; Load the address of the variable src into the HL register pair
    lxi     d, dst    ; Load the address of the variable dst into the DE register pair
    mvi     c, 0Ah    ; Set the loop counter C to 10

CopyLoop:
    mov     a, m      ; Copy the value in memory pointed to by the HL register pair into register A
    stax    d         ; Store the value in A at the memory address pointed to by DE
    inx     h         ; Increment the HL register pair by 1
    inx     d         ; Increment the value of the DE register pair by 1
    dcr     c         ; Decrement the C counter register by 1
    jnz     CopyLoop  ; Jump to the label CopyLoop until register C becomes 0

    hlt               ; Stop program execution

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