String array
A program that prints an array of strings (animal names) separated by a zero byte. Each string is printed on a new line.
Program source code
title .model small .stack 100h data segment public animals db "Dogs", 0, "Cats", 0, "Cattle", 0, "Goats", 0, "Camels", 0 db "Chickens", 0, "Ferrets", 0, "Yaks", 0, "Boars", 0, "Pigs", 0 data ends code segment public ; Start of the code segment assume ds:data, cs:code include Handyfar.inc ; Include the file with functions main proc ; Start of the main procedure call SetDataSegment ; Call the SetDataSegment procedure lea si, ds:[animals] ; Load the address of the animals variable into the si register mov cx, 10 ; Set the counter to 10 MainLoop: lodsb ; Load a byte from the source register si into the al register test al, al ; Perform a logical comparison of the value in the al register with 0 jz Skip ; If ZF=1, jump to the Skip label call PutChar ; Call the PutChar procedure jmp MainLoop ; Perform an unconditional jump to the MainLoop label Skip: call PrintNewLine ; Call the PrintNewLine procedure loop MainLoop ; 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
Dogs
Cats
Cattle
Goats
Camels
Chickens
Ferrets
Yaks
Boars
Pigs
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".