這些是使用WindowsAPI調(diào)用的Win 32和Win 64示例。他們是為MASM而不是NASM,但看看他們。您可以在這,這個文章。
;---ASM Hello World Win32 MessageBox.386.model flat, stdcall
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib.data
title db 'Win32', 0msg db 'Hello World', 0.codeMain:push 0 ; uType = MB_OK
push offset title ; LPCSTR lpCaption
push offset msg ; LPCSTR lpText
push 0 ; hWnd = HWND_DESKTOP
call MessageBoxApush eax ; uExitCode = MessageBox(...)call ExitProcessEnd Main;---ASM Hello World Win64 MessageBoxextrn MessageBoxA: PROC
extrn ExitProcess: PROC.data
title db 'Win64', 0msg db 'Hello World!', 0.code
main proc sub rsp, 28h
mov rcx, 0 ; hWnd = HWND_DESKTOP
lea rdx, msg ; LPCSTR lpText
lea r8, title ; LPCSTR lpCaption
mov r9d, 0 ; uType = MB_OK
call MessageBoxA
add rsp, 28h
mov ecx, eax ; uExitCode = MessageBox(...)
call ExitProcessmain endpEnd
若要使用MASM組裝和鏈接這些文件,請將其用于32位可執(zhí)行文件:
ml.exe [filename] /link /subsystem:windows
/defaultlib:kernel32.lib /defaultlib:user32.lib /entry:Main
或者對于64位可執(zhí)行文件:
ml64.exe [filename] /link /subsystem:windows
/defaultlib:kernel32.lib /defaultlib:user32.lib /entry:main