Skip to content

Instantly share code, notes, and snippets.

@mcandre
Last active March 26, 2024 15:14
Show Gist options
  • Save mcandre/4d7654bf994d0c13f6503b0ef25a3105 to your computer and use it in GitHub Desktop.
Save mcandre/4d7654bf994d0c13f6503b0ef25a3105 to your computer and use it in GitHub Desktop.
64-bit GNU assembler Hello World for Windows
# Build:
#
# as -o hello.obj
# ld -o hello.exe hello.obj -L C:\\tools\\mingw64\\x86_64-w64-mingw32\\lib -lkernel32
#
# Requires MinGW
.extern GetStdHandle
.extern WriteFile
.extern ExitProcess
.section .rodata
msg: .ascii "Hello World!\r\n"
.equ msg_len, .-msg
.equ stdout_query, -11
.section .data
stdout: .long 0
bytes_written: .long 0
.section .text
.global start
start:
mov $stdout_query, %rcx
call GetStdHandle
mov %rax, (stdout)
mov (stdout), %rcx
mov $msg, %rdx
mov $msg_len, %r8
mov $bytes_written, %r9
push $0
call WriteFile
xor %rcx, %rcx
call ExitProcess
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment