Hello world example in x86 assembly language for FreeBSD

This example program illustrates "Hello world" for the FreeBSD operating system in x86 assembly language.

        .global _start

        .text
_start:
        # write (1, message, 13)
        push    $13               # Number of bytes
        push    $message          # Address of string to output
        push    $1                # File handle 1 is stdout
        mov     $4, %eax          # System call 4 is write
        push    %eax
        int     $0x80

        # exit (0)
        push    $0                # Exit status
        mov     $1, %eax          # System call 1 is exit
        push    %eax
        int     $0x80

message:
        .ascii  "Hello, world\n"

(download)

To compile and run the program, use

cc -c hello.s && ld hello.o && ./a.out

Web links


Copyright © Ben Bullock 2009-2024. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com). / Privacy / Disclaimer