Skip to content

Instantly share code, notes, and snippets.

@mcandre
Last active April 22, 2025 18:26
Show Gist options
  • Save mcandre/b3664ffbeb4f5764b36a397fafb04f1c to your computer and use it in GitHub Desktop.
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
; 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
@kawaii-ghost
Copy link

Shadow store where ?

@sebanovo
Copy link

sebanovo commented Sep 7, 2024

section .data
    hello db 'Hello, World!', 0  
    helloLen equ $ - hello        

section .text
    global main
    extern ExitProcess, WriteConsoleA, GetStdHandle

main:
    sub rsp, 28h               
    mov rcx, -11                
    call GetStdHandle

    ; Escribir el mensaje en la consola
    mov r9, 0                
    mov r8, helloLen          
    mov rdx, hello            
    mov rcx, rax               
    call WriteConsoleA        

    ; Terminar el programa
    mov rcx, 0                 
    call ExitProcess            

@mcandre
Copy link
Author

mcandre commented Apr 22, 2025

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