Hello World using x86 assembler on Mac 0SX

You'll probably find it easier to build with gcc rather than trying to micro-manage the assembler and linker, e.g.

$ gcc helloWorld.s -o helloWorld

(You'll probably want to change _start to _main if you go this route.)

Incidentally, it can be instructive to start with a working C program, and study the generated asm from this. E.g.

#include <stdio.h>

int main(void)
{
    puts("Hello world!\n");

    return 0;
}

when compiled with gcc -Wall -O3 -m32 -fno-PIC hello.c -S -o hello.S generates:

    .cstring
LC0:
    .ascii "Hello world!\12\0"
    .text
    .align 4,0x90
.globl _main
_main:
    pushl   %ebp
    movl    %esp, %ebp
    subl    $24, %esp
    movl    $LC0, (%esp)
    call    _puts
    xorl    %eax, %eax
    leave
    ret
    .subsections_via_symbols

You might want to consider using this as a template for your own "Hello world" or other experimental asm programs, especially given that it already builds and runs:

$ gcc -m32 hello.S -o hello
$ ./hello 
Hello world!

One final comment: beware of taking examples from Linux-oriented asm books or tutorials and trying to apply them under OS X - there are important differences !


Try:

ld -e _start -arch x86_64 -o HelloWorld HelloWorld.S

then:

./HelloWorld

Info:

-e <entry point>
-arch <architecture>, You can check your architecture by uname -a 
-o <output file>