How to write hello world in assembly under Windows?
assembly, nasm, winapi, x86
Solution
NASM examples.
Calling libc stdio `printf`, implementing `int main(){ return printf(message); }`
; ----------------------------------------------------------------------------
; helloworld.asm
;
; This is a Win32 console program that writes "Hello, World" on one line and
; then exits. It needs to be linked with a C library.
; ----------------------------------------------------------------------------
global _main
extern _printf
section .text
_main:
push message
call _printf
add esp, 4
ret
message:
db 'Hello, World', 10, 0
Then run
nasm -fwin32 helloworld.asm
gcc helloworld.obj
a
There's also The Clueless Newbies Guide to Hello World in Nasm without the use of a C library. Then the code would look like this.
16-bit code with MS-DOS system calls: works in DOS emulators or in 32-bit Windows with NTVDM support. Can't be run "directly" (transparently) under any 64-bit Windows, because an x86-64 kernel can't use vm86 mode.
org 100h
mov dx,msg
mov ah,9
int 21h
mov ah,4Ch
int 21h
msg db 'Hello, World!',0Dh,0Ah,'$'
Build this into a `.com` executable so it will be loaded at `cs:100h` with all segment registers equal to each other (tiny memory model).
Good luck.
Problem
I wanted to write something basic in assembly under Windows. I'm using NASM, but I can't get anything working. How do I write and compile a hello world program without the help of C functions on Windows?