Floating-point array

A program that prints an array of double-precision floating-point numbers using the coprocessor (FPU) stack.

Program source code

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

data segment public
    fmtout db  "[%f] \0"
    array  dq  3.45, 4.54, -1.33, 7.54
    arrlen equ ($-array) / 8
data ends

code segment public                ; Start of the code segment
    assume  ds:data, cs:code
    include Handyfar.inc           ; Include the file with functions
    include Handymac.inc           ; Include the file with macros

    main proc                      ; Start of the main procedure
        call    SetDataSegment     ; Call the SetDataSegment procedure

        xor     si, si             ; Clear the si register, it will serve as the index
        mov     cx, arrlen         ; Copy the array length into the cx register
        lea     bx, ds:[array]     ; Load the address of the array into the ds:bx register

    @MainLoop:
        fld     qword ptr[bx+si]   ; 2nd: load the value at bx indexed by si onto the top of the stack
        lea     ax, ds:[fmtout]    ; 1st: load the address of the fmtout format string into ax
        call    PrintFormatString  ; Call the PrintFormatString procedure
        incq    si                 ; Increment the si index by 8
        loop    @MainLoop          ; Loop while the cx register is not equal to 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

[3.45] [4.54] [-1.33] [7.54]

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