A small NASM assembly demo that includes both a Linux example with a C harness and a native Windows console example.
hello.asm- a NASM x86-64 Linux assembly routine that writes a message to stdout using the LinuxsyscallAPI.main.c- a tiny C driver used only to invoke the Linux assembly routine three times.hello_windows.asm- a NASM x86-64 Windows console program that writes a message using the Windows API.hello.o- compiled Linux NASM object file (generated).hello- compiled Linux executable (generated).hello_windows.obj- compiled Windows NASM object file (generated).hello_windows.exe- compiled Windows executable (generated).
The Linux example is implemented in hello.asm, and main.c calls print_arken() three times to exercise that routine.
The Windows example is implemented in hello_windows.asm and writes directly to standard output with GetStdHandle and WriteFile.
Both examples print:
Hello, World!
- Linux x86-64 environment or WSL (Windows Subsystem for Linux)
nasmgcc
hello.asm is written for Linux x86-64 and uses syscall, so it is not directly compatible with native Windows.
- Windows PowerShell or another native Windows shell
nasmgccfrom MinGW-w64 or a compatible Windows GCC toolchain
hello_windows.asm uses the Windows x64 calling convention and calls functions from kernel32.
From the repository root in WSL or Linux:
nasm -f elf64 hello.asm -o hello.o
gcc main.c hello.o -o hello
./helloIf you want to avoid PIE-related linker warnings, use:
gcc -no-pie main.c hello.o -o helloFrom the repository root in PowerShell:
nasm -f win64 hello_windows.asm -o hello_windows.obj
gcc hello_windows.obj -o hello_windows.exe -lkernel32
.\hello_windows.exe- The assembly uses RIP-relative addressing for the message data.
- Use the Linux commands from WSL or Linux and the Windows commands from PowerShell. Mixing the two toolchains will fail at link time.
- If you rebuild the project, you can safely delete generated outputs such as
hello.o,hello,hello_windows.obj, andhello_windows.exebefore rerunning the build commands.