Over a million developers have joined DZone.

Hello Assambler

DZone's Guide to

Hello Assambler

· ·
Free Resource
The canonical Hello World program in assambler.

Compile it with:
nasm -f elf hello.s
ld -s -o hello hello.o

Helloworld is a function. It uses the write system call to print to stdout (file descriptor 1).

This is written in NASM (Intel) syntax, hence it will not work with gas, tasm or masm. It was written for Linux. The details may vary on other platforms.

Download NASM for free at http://nasm.sourceforge.net/

section .data
  hello: db "Hello world!",10
  hellolen: equ $ - hello

section .text
  global _start

  call helloworld

  mov eax,1 ; start exit procedure
  mov ebx,0

  int 80h

  mov eax,4 ; 4 is the code for the write system call
  mov ebx,1 ; 1 is the fd for stdout
  mov ecx,hello ; the address of the string
  mov edx,hellolen ; the length of the string

  int 80h ; trigger an interrupt; this should be 21h for DOS


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}