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

asmファイルの追加


startup.asm
.model flat, c
 
NULL			equ	0
STD_OUTPUT_HANDLE	equ	-11
 
CommandLineToArgvW	proto stdcall :ptr, :ptr
ExitProcess		proto stdcall :dword
GetCommandLineW		proto stdcall
GetStdHandle		proto stdcall :dword
WriteConsoleW		proto stdcall :dword, :ptr, :dword, :ptr, :ptr
wsprintfW		proto c :ptr, :ptr, :vararg
 
main	proto c :dword, :ptr
print1	proto c :ptr, :dword
 
.data
 
fmt1		word	'a','r','g','c',':',' ','%','d',0ah,0
fmt2		word	'%','d',':',0
fmt3		word	'[','%','s',']',0ah,0
 
.data?
 
hConsole	dword	?
 
.code
 
startup proc
	local	argc:dword
	local	argv:ptr
 
	invoke	GetStdHandle, STD_OUTPUT_HANDLE
	mov	hConsole, eax
 
	invoke	GetCommandLineW
	mov	edx, eax
	invoke	CommandLineToArgvW, edx, addr argc
	mov	argv, eax
 
	invoke	main, argc, argv
	invoke	ExitProcess, eax
	ret
startup endp
 
main proc uses esi edi,
	argc:dword, argv:ptr		; int argc, word** argv
 
	invoke	print1, addr fmt1, argc
 
	mov	esi, argv		; word** p = argv
	xor	edi, edi		; int n = 0
@@:
	mov	eax, dword ptr [esi]	; while (*p)
	test	eax, eax
	je	@f
	invoke	print1, addr fmt2, edi
	invoke	print1, addr fmt3, dword ptr [esi]
	inc	edi			; n++
	lea	esi, dword ptr [esi+4]	; p++
	jmp	@b
@@:
	mov	eax, 0
	ret
main endp
 
print1 proc fmt:ptr, param:dword
	local	buf[256]:word
	local	written:dword
 
	invoke	wsprintfW, addr buf, fmt, param
	mov	edx, eax	; len
	invoke	WriteConsoleW, hConsole, addr buf, edx, addr written, NULL
	ret
print1 endp
 
end startup
 

ビルド


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

実行


最終更新:2020年10月20日 19:48
添付ファイル