Using CVI Fmt and FmtOut in Assembly Code

The easiest way to print integer and floating-point values from Assembly Code to the Console

When working with EuroAssembler, it’s often useful to output information to the console. EuroAsm provides convenient macros for this purpose. Here’s a simple example:

EUROASM AutoSegment=Yes, CPU=X64, SIMD=AVX2
cvidemo PROGRAM Format=PE, Width=64, Model=Flat, IconFile=, Entry=main:

INCLUDE winscon.htm, winabi.htm, cpuext64.htm

WelcomeMsg D "Hello, CVI and EuroAssembler!",0
Buffer DB 80 * B
AnswerMsg D "EuroAsm: The Answer is ",0

main: nop
	StdOutput WelcomeMsg, Eol=Yes, Console=Yes ; standard EuroAsm Macro

    mov rax, 42
	StoD Buffer ; https://euroassembler.eu/maclib/cpuext64.htm#StoD 
	StdOutput AnswerMsg, Buffer, Eol=Yes, Console=Yes
; ...

But there is easiest way to do the same with Fmt/FmtOut functions from NI CVI. All what we need is just link to cvirt.lib, they will be called from cvirte.dll:

However, there’s an even easier way to achieve this using the Fmt and FmtOut functions from NI LabWindows/CVI. All you need is to link against cvirt.lib, which calls into cvirte.dll at runtime:

EUROASM AutoSegment=Yes, CPU=X64, SIMD=AVX2
cvidemo PROGRAM Format=PE, Width=64, Model=Flat, IconFile=, Entry=main:

INCLUDE winscon.htm, winabi.htm, cpuext64.htm

FmtBuf DB 80 * B
FmtMsg D "CVI The Answer is %%d",13,10,0
FortyTwo DB D 42

LINK cvirt.lib ; For Fmt and FmtOut
    
main: nop
	StdOutput WelcomeMsg, Eol=Yes, Console=Yes ; standard EuroAsm Macro
	
    mov rax, 42
	WinABI FmtOut, FmtMsg, rax ; Direct Output to the Console

 	WinABI FmtOut, FmtMsg, 42  ; From Constant

 	WinABI FmtOut, FmtMsg, [FortyTwo] ; From Memory
;...

A great feature is that this also works for floating-point variables:

FmtMsgF D "Float variable: %%f[p2] (Answer)",13,10,0
Numerator DO Q 42.0
Denominator DO Q 13.0
;...
	mov rbx, 42
	mov rdx, 13
    movq xmm0, rbx ; movq xmm0, [numerator]
    movq xmm1, rdx ; movq xmm1, [denominator]
    divsd xmm0, xmm1
	WinABI FmtOut, FmtMsgF, xmm0 ; Float Point
;...

Full code example:

;/==============================================================================
;/
;/ Title:		CVI Demo for Fmt and FmtOut Formatting Functions
;/ Purpose:		How to call these from Assembly
;/
;/ Created on:	06.10.2025 at 11:32:43 by AD.
;/
;/==============================================================================
EUROASM AutoSegment=Yes, CPU=X64, SIMD=AVX2
cvidemo PROGRAM Format=PE, Width=64, Model=Flat, IconFile=, Entry=Start:

INCLUDE winscon.htm, winabi.htm, cpuext64.htm

WelcomeMsg D "Hello, CVI and EuroAssembler!",0
Buffer DB 80 * B
AnswerMsg D "EuroAsm: The Answer is ",0

FmtBuf DB 80 * B
FmtMsg D "CVI The Answer is %%d",13,10,0
FortyTwo DB D 42

FmtMsgF D "Float variable: %%f[p2] (Answer)",13,10,0
FmtMsgFO D "%%s<%%f[p1] Divided by %%f[p1] is %%f[p2]",13,10,0
Numerator DO Q 42.0
Denominator DO Q 13.0

InputNumerator D "Input Numerator (Float) :",0
InputDenominator D "Input Denominator (Float) :",0
BufferNumerator DB 80 * B
BufferDenominator DB 80 * B
ScanFmt D "%%s>%%f",0
ScanInFmt D "%%l>%%f",0

LINK cvirt.lib
    
Start: nop
;/==============================================================================
;/ Standard EuroAssembler
;/
	StdOutput WelcomeMsg, Eol=Yes, Console=Yes ; standard EuroAsm Macro

    mov rax, 42
	StoD Buffer ; https://euroassembler.eu/maclib/cpuext64.htm#StoD 
	StdOutput AnswerMsg, Buffer, Eol=Yes, Console=Yes

;/==============================================================================
;/ CVI:
;/
	WinABI Fmt, FmtBuf, FmtMsg, rax ; Fmt to Buffer
	StdOutput FmtBuf,  Console=Yes  ; Buffer Output

    mov rax, 42
	WinABI FmtOut, FmtMsg, rax ; Direct Output to the Console

 	WinABI FmtOut, FmtMsg, 42  ; From Constant

 	WinABI FmtOut, FmtMsg, [FortyTwo] ; From Memory

;/==============================================================================
;/ Float Point:
;/
	mov rbx, 42
	mov rdx, 13
    movq xmm0, rbx ; movq xmm0, [numerator]
    movq xmm1, rdx ; movq xmm1, [denominator]
    divsd xmm0, xmm1
	WinABI FmtOut, FmtMsgF, xmm0 ; Float Point

    movq xmm0, [Numerator]
    movq xmm1, [Denominator]
    divsd xmm0, xmm1
	WinABI FmtOut, FmtMsgFO, [Numerator], [Denominator], xmm0
	
;/==============================================================================
;/ With Input from EuroAssembler:
;/
	StdOutput InputNumerator, Console=Yes ; standard EuroAsm Macro
	StdInput BufferNumerator, Console=Yes
	WinABI Scan, BufferNumerator, ScanFmt, Numerator 
	StdOutput InputDenominator, Console=Yes ; standard EuroAsm Macro
	StdInput BufferDenominator, Console=Yes
	WinABI Scan, BufferDenominator, ScanFmt, Denominator
    movq xmm0, [Numerator]
    movq xmm1, [Denominator]
    divsd xmm0, xmm1
	WinABI FmtOut, FmtMsgFO, [Numerator], [Denominator], xmm0

;/==============================================================================
;/ With Input from NI CVI:
;/
	WinABI FmtOut, InputNumerator
	WinABI ScanIn, ScanInFmt, Numerator 
	WinABI FmtOut, InputDenominator
	WinABI ScanIn, ScanInFmt, Denominator 
    movq xmm0, [Numerator]
    movq xmm1, [Denominator]
    divsd xmm0, xmm1
	WinABI FmtOut, FmtMsgFO, [Numerator], [Denominator], xmm0

	TerminateProgram
ENDPROGRAM

Output:

>cvidemo.exe
Hello, CVI and EuroAssembler!
EuroAsm: The Answer is 42
CVI The Answer is 42
CVI The Answer is 42
CVI The Answer is 42
CVI The Answer is 42
Float variable: 3.23 (Answer)
42.0 Divided by 13.0 is 3.23
Input Numerator (Float) :1
Input Denominator (Float) :2
1.0 Divided by 2.0 is 0.50
Input Numerator (Float) :3
Input Denominator (Float) :4
3.0 Divided by 4.0 is 0.75

EuroAssembler

Introductory Formatting and Scanning Examples

Formatting Functions and Scanning Functions

Example Code Using Fmt/FmtFile/FmtOut

Example Code Using Scan/ScanFile/ScanIn

Formatting and I/O Library Function Tree