如何在Windows下用汇编程序编写Hello World?我想在Windows下编写一些基本的汇编语言,我正在使用NASM,但是我不能让任何东西工作。如何在Windows上不借助C函数编写并编译Hello World?
3 回答
慕村225694
TA贡献1880条经验 获得超4个赞
global _main extern _GetStdHandle@4 extern _WriteFile@20 extern _ExitProcess@4 section .text _main: ; DWORD bytes; mov ebp, esp sub esp, 4 ; hStdOut = GetstdHandle( STD_OUTPUT_HANDLE) push -11 call _GetStdHandle@4 mov ebx, eax ; WriteFile( hstdOut, message, length(message), &bytes, 0); push 0 lea eax, [ebp-4] push eax push (message_end - message) push message push ebx call _WriteFile@20 ; ExitProcess(0) push 0 call _ExitProcess@4 ; never here hlt message: db 'Hello, World', 10message_end:
nasm -fwin32 hello.asm link /subsystem:console /nodefaultlib /entry:main hello.obj
FFIVE
TA贡献1797条经验 获得超6个赞
;---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
ml.exe [filename] /link /subsystem:windows /defaultlib:kernel32.lib /defaultlib:user32.lib /entry:Main
ml64.exe [filename] /link /subsystem:windows /defaultlib:kernel32.lib /defaultlib:user32.lib /entry:main
- 3 回答
- 0 关注
- 2034 浏览
添加回答
举报
0/150
提交
取消