Adding all elements of an array
In the following program example we will add all elements of an array. The result of the addition will be in the accumulator register.
Program source code
; Author: Evgeny Sergeevich Dovgopolov array: db 01h, 02h, 03h, 04h, 05h, 06h, 07h, 08h, 09h, 0Ah, 0Bh, 0Ch, 0Dh, 0Eh, 0Fh, db 10h, 11h, 12h, 13h, 14h arrsum: db 00h main: mvi a, 00h ; Clear the value of the addition result mvi c, 14h ; Set the loop counter C to 20 lxi h, array ; Load the address of the variable array into the HL register pair SumLoop: add m ; Add the value in register A to the value in the memory location inx h ; Increment the HL register pair by 1 dcr c ; Decrement the C counter register by 1 jnz SumLoop ; Jump to the label SumLoop until register C becomes 0 sta arrsum ; Save the value of register A in memory (arrsum) hlt ; Stop program execution
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".