開発環境 Microsoft Visual Studio Community 2019
実行環境 Microsoft Windows 10 Home (64bit)
プロジェクト テンプレート 空のプロジェクト(C++)
プロジェクト名 vprint

asmファイルの追加


vprint.asm
.model flat, c
 
NULL			equ	0
STD_OUTPUT_HANDLE	equ	-11
 
ExitProcess		proto stdcall :dword
GetStdHandle		proto stdcall :dword
WriteConsoleA		proto stdcall :dword, :ptr, :dword, :ptr, :ptr
wvsprintfA		proto stdcall :ptr, :ptr, :ptr
 
debug	proto c :ptr, :vararg
 
.data
 
fmt1	byte	'0x%X (%d)', 0ah, 0
fmt2	byte	'%s %d %c', 0ah, 0
msg	byte	'hello', 0
 
.data?
 
hConsole	dword	?
 
.code
 
start proc
	invoke	GetStdHandle, STD_OUTPUT_HANDLE
	mov	hConsole, eax
 
	invoke	debug, addr fmt1, 123, 456
	invoke	debug, addr fmt2, addr msg, 42, '%'
 
	invoke	ExitProcess, 0
	ret
start endp
 
debug proc fmt:ptr, va:vararg
	local	written:dword
	local	buf[1024]:byte
 
	invoke	wvsprintfA, addr buf, fmt, addr va
	mov	edx, eax	; len
	invoke	WriteConsoleA, hConsole, addr buf, edx, addr written, NULL
	ret
debug endp
 
end start
 

ビルド


  • リンカー
システム サブシステム コンソール (/SUBSYSTEM:CONSOLE)

実行


最終更新:2020年10月21日 11:40
添付ファイル