Last active
April 22, 2025 18:26
-
-
Save mcandre/b3664ffbeb4f5764b36a397fafb04f1c to your computer and use it in GitHub Desktop.
64-bit Windows hello world assembler example, works with Command Prompt, PowerShell, and cygwin-like environments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Build: | |
; | |
; nasm -f win64 hello.asm | |
; powershell -Command "~\\vsexec.bat link /entry:start /subsystem:console hello.obj kernel32.lib" | |
; | |
; The PowerShell wrapper ensures that the linker (either link.exe or golink) receives the correct flags, | |
; even when the linker command is executed from cygwin-like environments such as Git Bash. | |
; | |
; vsexec.bat: | |
; call "C:\\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" amd64 %* | |
; | |
; Requires nasm, Visual Studio build tools, e.g. | |
; nasm, visualstudio2017buildtools, visualstudio2017-workload-vctools Chocolatey packages | |
extern GetStdHandle | |
extern WriteFile | |
extern ExitProcess | |
section .rodata | |
msg db "Hello World!", 0x0d, 0x0a | |
msg_len equ $-msg | |
stdout_query equ -11 | |
section .data | |
stdout dw 0 | |
bytes_written dw 0 | |
section .text | |
global start | |
start: | |
mov rcx, stdout_query | |
call GetStdHandle | |
mov [rel stdout], rax | |
mov rcx, [rel stdout] | |
mov rdx, msg | |
mov r8, msg_len | |
mov r9, bytes_written | |
push qword 0 | |
call WriteFile | |
xor rcx, rcx | |
call ExitProcess |
sebanovo
commented
Sep 7, 2024
Note that Windows no longer maintains a stable below-C ABI. The vast majority of online Windows assembler tutorials no longer work.
Unknown about 32 bit support.
Advise targeting a modern programming language like Go or Rust.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment