開発環境 Microsoft Visual Studio Community 2017
実行環境 Microsoft Windows 10 Home (64bit)

  • 任意のディレクトリを用意する(例 C:\Projects\masm64\test64)

test64.asm
comment *
	test64.asm for ML64
 
ml64 /c /Fl test64.asm
link /entry:start /subsystem:windows test64
*
 
; kernel32
extern __imp_ExitProcess: proc
 
; user32
extern __imp_MessageBoxA: proc
extern __imp_wsprintfA: proc
 
; lib
includelib kernel32.lib
includelib user32.lib
 
; define
NULL		equ	0
MB_OK		equ	0
 
.const
caption		db	"test64", 0
fmt		db	"sum=[%d]", 0
 
.code
i$ = 20h
sum$ = 24h
buf$ = 28h
start proc
	sub	rsp, 28h + 30h
 
	mov	dword ptr sum$[rsp], 0		; int sum = 0
 
	mov	dword ptr i$[rsp], 1		; int i = 1
	jmp	short $LN4@start
$LN2@start:
	mov	eax, dword ptr i$[rsp]		; i++
	inc	eax
	mov	dword ptr i$[rsp], eax
$LN4@start:
	cmp	dword ptr i$[rsp], 10		; i <= 10
	jg	short $LN3@start
	mov	edx, dword ptr i$[rsp]
	mov	ecx, dword ptr sum$[rsp]
	call	f_add
	mov	dword ptr sum$[rsp], eax
	jmp	short $LN2@start
$LN3@start:
 
	; wsprintfA(buf, fmt, sum)
	mov	r8d, dword ptr sum$[rsp]
	lea	rdx, fmt
	lea	rcx, qword ptr buf$[rsp]
	call	qword ptr __imp_wsprintfA
 
	; MessageBoxA(NULL, buf, caption, MB_OK)
	mov	r9, MB_OK
	lea	r8, caption
	lea	rdx, qword ptr buf$[rsp]
	mov	rcx, NULL
	call	qword ptr __imp_MessageBoxA
 
	; ExitProcess(0)
	mov	rcx, 0
	call	qword ptr __imp_ExitProcess
start endp
 
.code
f_add proc
	lea	eax, dword ptr [rcx+rdx]
	ret
f_add endp
 
end
 

test.bat
path %path%;"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\Hostx64\x64"
set lib="C:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\um\x64"
cmd
 

test64.lst
Microsoft (R) Macro Assembler (x64) Version 14.11.25547.0   11/04/17 20:16:53
test64.asm						     Page 1 - 1
 
 
				comment *
					test64.asm for ML64
 
				ml64 /c /Fl test64.asm
				link /entry:start /subsystem:windows test64
				*
 
				; kernel32
				extern __imp_ExitProcess: proc
 
				; user32
				extern __imp_MessageBoxA: proc
				extern __imp_wsprintfA: proc
 
				; lib
				includelib kernel32.lib
				includelib user32.lib
 
				; define
 = 00000000			NULL		equ	0
 = 00000000			MB_OK		equ	0
 
 00000000			.const
 00000000 74 65 73 74 36	caption		db	"test64", 0
	   34 00
 00000007 73 75 6D 3D 5B	fmt		db	"sum=[%d]", 0
	   25 64 5D 00
 
 00000000			.code
 = 00000020			i$ = 20h
 = 00000024			sum$ = 24h
 = 00000028			buf$ = 28h
 00000000			start proc
 00000000  48/ 83 EC 58			sub	rsp, 28h + 30h
 
 00000004  C7 44 24 24			mov	dword ptr sum$[rsp], 0		; int sum = 0
	   00000000
 
 0000000C  C7 44 24 20			mov	dword ptr i$[rsp], 1		; int i = 1
	   00000001
 00000014  EB 0A			jmp	short $LN4@start
 00000016			$LN2@start:
 00000016  8B 44 24 20			mov	eax, dword ptr i$[rsp]		; i++
 0000001A  FF C0			inc	eax
 0000001C  89 44 24 20			mov	dword ptr i$[rsp], eax
 00000020			$LN4@start:
 00000020  83 7C 24 20 0A		cmp	dword ptr i$[rsp], 10		; i <= 10
 00000025  7F 13			jg	short $LN3@start
 00000027  8B 54 24 20			mov	edx, dword ptr i$[rsp]
 0000002B  8B 4C 24 24			mov	ecx, dword ptr sum$[rsp]
 0000002F  E8 0000004A			call	f_add
 00000034  89 44 24 24			mov	dword ptr sum$[rsp], eax
 00000038  EB DC			jmp	short $LN2@start
 0000003A			$LN3@start:
 
					; wsprintfA(buf, fmt, sum)
 0000003A  44/ 8B 44 24			mov	r8d, dword ptr sum$[rsp]
	   24
 0000003F  48/ 8D 15			lea	rdx, fmt
	   00000007 R
 00000046  48/ 8D 4C 24			lea	rcx, qword ptr buf$[rsp]
	   28
 0000004B  FF 15 00000000 E		call	qword ptr __imp_wsprintfA
 
					; MessageBoxA(NULL, buf, caption, MB_OK)
 00000051  49/ C7 C1			mov	r9, MB_OK
	   00000000
 00000058  4C/ 8D 05			lea	r8, caption
	   00000000 R
 0000005F  48/ 8D 54 24			lea	rdx, qword ptr buf$[rsp]
	   28
 00000064  48/ C7 C1			mov	rcx, NULL
	   00000000
 0000006B  FF 15 00000000 E		call	qword ptr __imp_MessageBoxA
 
					; ExitProcess(0)
 00000071  48/ C7 C1			mov	rcx, 0
	   00000000
 00000078  FF 15 00000000 E		call	qword ptr __imp_ExitProcess
 0000007E			start endp
 
 0000007E			.code
 0000007E			f_add proc
 0000007E  8D 04 11			lea	eax, dword ptr [rcx+rdx]
 00000081  C3				ret
 00000082			f_add endp
 
				end
 
 
Microsoft (R) Macro Assembler (x64) Version 14.11.25547.0   11/04/17 20:16:53
test64.asm						     Symbols 2 - 1
 
 
 
 
Segments:
 
                N a m e                  Length   Align   Class
 
CONST  . . . . . . . . . . . . .	 00000010 16	  'CONST'	 ReadOnly
 
 
Procedures, parameters, and locals:
 
                N a m e                 Type     Value    Attr
 
f_add  . . . . . . . . . . . . .	P 	 0000007E _TEXT	Length= 00000004 Public
start  . . . . . . . . . . . . .	P 	 00000000 _TEXT	Length= 0000007E Public
  $LN2@start . . . . . . . . . .	L 	 00000016 _TEXT	
  $LN4@start . . . . . . . . . .	L 	 00000020 _TEXT	
  $LN3@start . . . . . . . . . .	L 	 0000003A _TEXT	
 
 
Symbols:
 
                N a m e                 Type     Value    Attr
 
MB_OK  . . . . . . . . . . . . .	Number	 00000000h   
NULL . . . . . . . . . . . . . .	Number	 00000000h   
__imp_ExitProcess  . . . . . . .	L 	 00000000 External
__imp_MessageBoxA  . . . . . . .	L 	 00000000 External
__imp_wsprintfA  . . . . . . . .	L 	 00000000 External
buf$ . . . . . . . . . . . . . .	Number	 00000028h   
caption  . . . . . . . . . . . .	Byte	 00000000 CONST	
fmt  . . . . . . . . . . . . . .	Byte	 00000007 CONST	
i$ . . . . . . . . . . . . . . .	Number	 00000020h   
sum$ . . . . . . . . . . . . . .	Number	 00000024h   
 
	   0 Warnings
	   0 Errors
 



参考にしたVisual C++

ソリューション構成:Release
ソリューション プラットフォーム:x64

プロジェクトのプロパティ
ツリー 項目
構成プロパティ/C/C++/最適化 最適化 実行速度の最大化 (/O2)など
構成プロパティ/C/C++/出力ファイル アセンブリの出力 アセンブリコード、コンピューター語コード、ソースコード (/FAcs)など

test64.c
#include <Windows.h>
 
int f_add(int a, int b)
{
	return a + b;
}
 
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	BYTE buf[20];
	int sum = 0;
	int i;
 
	for (i = 1; i <= 10; i++) {
		sum = f_add(sum, i);
	}
	wsprintfA(buf, "sum=[%d]", sum);	// ULONG64 %I64u
	MessageBoxA(NULL, buf, "test64", MB_OK);
	ExitProcess(0);
//	return 0;
}
 

test64.cod
; Listing generated by Microsoft (R) Optimizing Compiler Version 19.11.25547.0 
 
include listing.inc
 
INCLUDELIB OLDNAMES
 
EXTRN	__imp_ExitProcess:PROC
EXTRN	__imp_wsprintfA:PROC
EXTRN	__imp_MessageBoxA:PROC
EXTRN	__security_check_cookie:PROC
$SG4294967289 DB 'sum=[%d]', 00H
	ORG $+3
$SG4294967288 DB 'test64', 00H
_DATA	ENDS
PUBLIC	WinMain
PUBLIC	f_add
EXTRN	__GSHandlerCheck:PROC
EXTRN	__security_cookie:QWORD
;	COMDAT pdata
pdata	SEGMENT
$pdata$WinMain DD imagerel $LN6
	DD	imagerel $LN6+165
	DD	imagerel $unwind$WinMain
pdata	ENDS
;	COMDAT xdata
xdata	SEGMENT
$unwind$WinMain DD 012719H
	DD	0a218H
	DD	imagerel __GSHandlerCheck
	DD	040H
xdata	ENDS
; Function compile flags: /Odtp
; File c:\projects\vc++\test64\test64.c
;	COMDAT f_add
_TEXT	SEGMENT
a$ = 8
b$ = 16
f_add	PROC						; COMDAT
 
; 4    : {
 
  00000	89 54 24 10	 mov	 DWORD PTR [rsp+16], edx
  00004	89 4c 24 08	 mov	 DWORD PTR [rsp+8], ecx
 
; 5    : 	return a + b;
 
  00008	8b 44 24 10	 mov	 eax, DWORD PTR b$[rsp]
  0000c	8b 4c 24 08	 mov	 ecx, DWORD PTR a$[rsp]
  00010	03 c8		 add	 ecx, eax
  00012	8b c1		 mov	 eax, ecx
 
; 6    : }
 
  00014	c3		 ret	 0
f_add	ENDP
_TEXT	ENDS
; Function compile flags: /Odtp
; File c:\projects\vc++\test64\test64.c
;	COMDAT WinMain
_TEXT	SEGMENT
i$ = 32
sum$ = 36
buf$ = 40
__$ArrayPad$ = 64
hInstance$ = 96
hPrevInstance$ = 104
lpCmdLine$ = 112
nCmdShow$ = 120
WinMain	PROC						; COMDAT
 
; 9    : {
 
$LN6:
  00000	44 89 4c 24 20	 mov	 DWORD PTR [rsp+32], r9d
  00005	4c 89 44 24 18	 mov	 QWORD PTR [rsp+24], r8
  0000a	48 89 54 24 10	 mov	 QWORD PTR [rsp+16], rdx
  0000f	48 89 4c 24 08	 mov	 QWORD PTR [rsp+8], rcx
  00014	48 83 ec 58	 sub	 rsp, 88			; 00000058H
  00018	48 8b 05 00 00
	00 00		 mov	 rax, QWORD PTR __security_cookie
  0001f	48 33 c4	 xor	 rax, rsp
  00022	48 89 44 24 40	 mov	 QWORD PTR __$ArrayPad$[rsp], rax
 
; 10   : 	BYTE buf[20];
; 11   : 	int sum = 0;
 
  00027	c7 44 24 24 00
	00 00 00	 mov	 DWORD PTR sum$[rsp], 0
 
; 12   : 	int i;
; 13   : 
; 14   : 	for (i = 1; i <= 10; i++) {
 
  0002f	c7 44 24 20 01
	00 00 00	 mov	 DWORD PTR i$[rsp], 1
  00037	eb 0a		 jmp	 SHORT $LN4@WinMain
$LN2@WinMain:
  00039	8b 44 24 20	 mov	 eax, DWORD PTR i$[rsp]
  0003d	ff c0		 inc	 eax
  0003f	89 44 24 20	 mov	 DWORD PTR i$[rsp], eax
$LN4@WinMain:
  00043	83 7c 24 20 0a	 cmp	 DWORD PTR i$[rsp], 10
  00048	7f 13		 jg	 SHORT $LN3@WinMain
 
; 15   : 		sum = f_add(sum, i);
 
  0004a	8b 54 24 20	 mov	 edx, DWORD PTR i$[rsp]
  0004e	8b 4c 24 24	 mov	 ecx, DWORD PTR sum$[rsp]
  00052	e8 00 00 00 00	 call	 f_add
  00057	89 44 24 24	 mov	 DWORD PTR sum$[rsp], eax
 
; 16   : 	}
 
  0005b	eb dc		 jmp	 SHORT $LN2@WinMain
$LN3@WinMain:
 
; 17   : 	wsprintfA(buf, "sum=[%d]", sum);	// ULONG64 %I64u
 
  0005d	44 8b 44 24 24	 mov	 r8d, DWORD PTR sum$[rsp]
  00062	48 8d 15 00 00
	00 00		 lea	 rdx, OFFSET FLAT:$SG4294967289
  00069	48 8d 4c 24 28	 lea	 rcx, QWORD PTR buf$[rsp]
  0006e	ff 15 00 00 00
	00		 call	 QWORD PTR __imp_wsprintfA
 
; 18   : 	MessageBoxA(NULL, buf, "test64", MB_OK);
 
  00074	45 33 c9	 xor	 r9d, r9d
  00077	4c 8d 05 00 00
	00 00		 lea	 r8, OFFSET FLAT:$SG4294967288
  0007e	48 8d 54 24 28	 lea	 rdx, QWORD PTR buf$[rsp]
  00083	33 c9		 xor	 ecx, ecx
  00085	ff 15 00 00 00
	00		 call	 QWORD PTR __imp_MessageBoxA
 
; 19   : 	ExitProcess(0);
 
  0008b	33 c9		 xor	 ecx, ecx
  0008d	ff 15 00 00 00
	00		 call	 QWORD PTR __imp_ExitProcess
$LN5@WinMain:
 
; 20   : //	return 0;
; 21   : }
 
  00093	48 8b 4c 24 40	 mov	 rcx, QWORD PTR __$ArrayPad$[rsp]
  00098	48 33 cc	 xor	 rcx, rsp
  0009b	e8 00 00 00 00	 call	 __security_check_cookie
  000a0	48 83 c4 58	 add	 rsp, 88			; 00000058H
  000a4	c3		 ret	 0
WinMain	ENDP
_TEXT	ENDS
END
 
最終更新:2017年11月04日 20:39