The first 10 natural numbers

A program that prints the first 10 natural numbers using a loop.

Program source code

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

data segment public
    string db "Natural numbers: \0"
    fmtstr db "[%d] \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     ax, ds:[string]    ; Load the address of the string variable into the ax register
        call    WriteString        ; Call the WriteString procedure

        mov     cx, 1              ; Set the cx counter register to 1

    MainLoop:
        push    cx                 ; 2nd: save the cx counter register value on the stack
        lea     ax, ds:[fmtstr]    ; 1st: load the address of the fmtstr format string into the ax register
        call    PrintFormatString  ; Call the PrintFormatString procedure
        add     sp, 2              ; Align the stack
        inc     cx                 ; Increment the cx counter register by 1
        cmp     cx, 10             ; Compare the cx register value with the number 10
        jbe     MainLoop           ; If CX is less than or equal to 10, jump to MainLoop

        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

Natural numbers: [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

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