Never been to DZone Snippets before?

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

About this user

Alexandru Scvortov

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Hello assambler

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/

   1  
   2  section .data
   3    hello: db "Hello world!",10
   4    hellolen: equ $ - hello
   5  
   6  section .text
   7    global _start
   8  
   9  _start:
  10    call helloworld
  11  
  12    mov eax,1 ; start exit procedure
  13    mov ebx,0
  14  
  15    int 80h
  16  
  17  helloworld:
  18    mov eax,4 ; 4 is the code for the write system call
  19    mov ebx,1 ; 1 is the fd for stdout
  20    mov ecx,hello ; the address of the string
  21    mov edx,hellolen ; the length of the string
  22  
  23    int 80h ; trigger an interrupt; this should be 21h for DOS
  24  
  25    ret
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS