Your code is a 32-bit build. Compilation on Snow Leopard is 64-bit by default, but you can use gcc -m32 to compile 32-bit code. Of course, there are options that you can pass to as and ld , but I found that remembering that only the option for gcc was sufficient, as it is an interface to all of these things.
Use gcc to show you an example of assembly code that works: enter the minimum C function in test.c and use gcc -S test.c to create the assembly in test.s.
Example:
int x; void f(void) { int i; for (i = 0; i < 5; i++) x = x + 1; }
compiled in the assembly on this Leopard Mac:
.text .globl _f _f: pushl %ebp movl %esp, %ebp subl $24, %esp call L6 "L00000000001$pb": L6: popl %ecx movl $0, -12(%ebp) jmp L2 L3: leal L_x$non_lazy_ptr-"L00000000001$pb"(%ecx), %eax movl (%eax), %eax movl (%eax), %eax leal 1(%eax), %edx leal L_x$non_lazy_ptr-"L00000000001$pb"(%ecx), %eax movl (%eax), %eax movl %edx, (%eax) leal -12(%ebp), %eax incl (%eax) L2: cmpl $4, -12(%ebp) jle L3 leave ret .comm _x,4,2 .section __IMPORT,__pointers,non_lazy_symbol_pointers L_x$non_lazy_ptr: .indirect_symbol _x .long 0 .subsections_via_symbols
You can make this easier with the gcc -fno-pic option:
.text .globl _f _f: pushl %ebp movl %esp, %ebp subl $24, %esp movl $0, -12(%ebp) jmp L2 L3: movl _x, %eax incl %eax movl %eax, _x leal -12(%ebp), %eax incl (%eax) L2: cmpl $4, -12(%ebp) jle L3 leave ret .comm _x,4,2 .subsections_via_symbols
In Snow Leopard, you get a 64-bit build (amd64). You can get the same on Leopard using the -m64 gcc option, and you can get the same on Snow Leopard that you get gcc on Leopard with the -m32 option.