Author Topic: FreeBSD 64 bit helloworld example.  (Read 11701 times)

Offline Mathi

  • Jr. Member
  • *
  • Posts: 82
  • Country: in
    • Win32NASM
FreeBSD 64 bit helloworld example.
« on: January 18, 2012, 06:16:53 PM »
I registered for a free online shell account and the box happened to be a FreeBSD amd64 machine.

Tried a helloworld program in nasm.
Finally got solved after i stumbled across this page.

The only difference from the linux version was the difference in the syscall numbers.


Also check the calling convention details from

A.2 AMD64 Linux Kernel Conventions  (Page 123)
A.2.1 Calling Conventions

Code: [Select]
;; Assemble with
;; nasm -felf64 hello.asm
;; Link with
;; ld -o hello hello.o

section .data
    message db  "Hello World!",10
    MSGLEN equ $-message

section .text
    global _start


        ; print the string using write() system call
        mov     rdx, MSGLEN
        mov     rsi, dword message
        mov     rdi, 1
        mov     rax, 4

        ; exit from the application here
        mov     rax, 1
        xor     edi, edi