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.

Up vote 6 down vote favorite 4 share g+ share fb share tw.

I am trying to dive into some x86 assembly programming on my Mac, but am having trouble producing an executable. The problem seems to be at the linking stage. HelloWorld.

S: . Data HelloWorldString: . Ascii "text .

Globl _start _start: # load all the arguments for write() movl $4, %eax movl $1, %ebx movl $HelloWorldString, %ecx movl $12, %edx # raises software interrupt to call write() int $0x80 # call exit() movl $1, %eax movl $0, %ebx int $0x80 Assemble the program: as -o helloWorld. O helloWorld. S Link the object file: ld -o helloWorld helloWorld.

O The error I get at this point is: ld: could not find entry point "start" (perhaps missing crt1. O) for inferred architecture x86_64 Any advice on what I'm doing wrong / missing would be very helpful. Thanks osx assembly linker x86 assembler link|improve this question edited Dec 4 '10 at 20:57starblue19.7k22258 asked Nov 26 '10 at 22:24darren5,75811033 100% accept rate.

2 I know I'm a bit late, but you need to change _start to start. – sidyll Aug 12 '11 at 21:40.

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 int main(void) { puts("\n"); return 0; } when compiled with gcc -Wall -O3 -m32 -fno-PIC hello. C -S -o hello.

S generates: . Cstring LC0: . Ascii "\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 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 -arch , You can check your architecture by uname -a -o.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions