DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Hello Assambler

05.02.2007
| 4362 views |
  • submit to reddit
        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

_start:
  call helloworld

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

  int 80h

helloworld:
  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

  ret