Array reversal
In the following program example we will reverse an array.
Program source code
; Author: Evgeny Sergeevich Dovgopolov array: db 0Ah, 09h, 08h, 07h, 06h, 05h, 04h, 03h, 02h, 01h main: lxi h, array ; Load the address of the variable array into the HL register pair lxi d, array+09h ; Load the address of the variable array into the HL register pair with an offset of + 9 mvi c, 05h ; Set the loop counter C to 5 ReverseLoop: ldax d ; Load the value at the memory address (array+offset) into accumulator A mov b, m ; Copy the value in memory pointed to by the HL register pair into B mov m, a ; Copy the value of A into the memory pointed to by the HL register pair mov a, b ; Copy the value of register B 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 dcx d ; Decrement the value of the DE register pair by 1 dcr c ; Decrement the C counter register by 1 jnz ReverseLoop ; Jump to the label ReverseLoop until C becomes 0 hlt ; Stop program execution
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".