Hello World in NetBSD x86_64 assembly

Submitted by Fekete Zoltán on

Here is the code itself, hello.asm

.section .note.netbsd.ident, "a"
    .int 0x00000007 # Name size
    .int 0x00000004 # Desc size
    .int 0x00000001 # value 0x01
    .ascii "NetBSD", "\0", "\0" # "NetBSD\0\0"
    .int 1000000000 # __NetBSD_Version__ (please see <sys/param.h>)

.section .text
    .global _start
    
_start:
    mov $0x04, %rax # write (please see sys/syscall.h) 
    mov $0x01, %rdi # first arg, file descriptor
    mov $msg, %rsi  # second arg, the string
    mov $len, %rdx  # third arg, length of the string
    int  $0x80      # syscall
    
    mov $0x01, %rax # exit (please see sys/syscall.h)
    mov $0x00, %rdi # first param, return value EXIT_SUCCESS
    int $0x80       # syscall
    
.section .data
    msg:     .asciz "Hello World!\n" # null teminated string
    len =  . - msg    
 

Compile

as hello.asm -o hello.o

Link

ld hello.o -o hello

Run

./hello

Further reading material

Using the GNU Assembler

x86_64 ABI specification