Nasm, macho and Macos problem



I'm a Mac user, I work on MAC OS X 10.4.11.

I can't execute a binary file create with NASM (macho output). Sistem
say me:"cannot execute".


I've installed NASM
nasm -v
NASM version 0.98.40 compiled on Nov 21 2007

So I've also macho to work on a valid output file for MACOS
nasm -hf
valid output formats for -f are (`*' denotes default):
macho NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X object files

I've compiled a "hello world" sample file.

Hello.asm
---------------------start code--------------------
section .text ; start of the code indicator
global _start ; make the main function
externally visible
section .data ; beginning of our data
section
msg db "Hello, World!",0xa ; string with a carriage-
return
len equ $ - msg ; string length in bytes
_syscall: ; declaring a kernel call function
int 0x80 ; make the system call
ret ; return to the caller
_start: ; entry point for linker
; write our string to standard output
push dword len ; message length
push dword msg ; message to write
push dword 1 ; file descriptor value
mov eax, 0x4 ; system call number (sys_write)
call _syscall ; call the kernel
add esp, 12 ; clean the stack
push dword 0 ; exit code
mov eax, 0x1 ; system call number (sys_exit)
call _syscall ; make the system call
---------------------end--------------------

So, I do
nasm -f macho hello.asm

I've now an hello.o file

I create Linker:
ld -e _start -o hello hello.o

Now, I should have a executable file.

But if I do:
../hello

Sistem answers me:
-bash: ./hello: cannot execute binary file

What's my damn problem??
Have u ideas?

(sorry for my bad english)

Tnx,
Giuseppe

.



Relevant Pages

  • Re: which book to start with...?
    ... Herbert finds Intel syntax illogical, confusing, and generally distasteful to use. ... And that's just the ELF header! ... There's also code around - Chuck posted a version for Fasm and Nasm a while ago - that *reads* the ELF header, ... is there any chace that strip can damage execute or object files or is it always safe to use even with s option? ...
    (alt.lang.asm)
  • Re: which book to start with...?
    ... The CPU *would* execute it, ... a hello world app with a infinite loop indicates ~10Mb of physical memory use in top. ... that Nasm puts its name in a .comment section...). ... anyway now my 0.98.39 install was overwritten by 2.0 compilation. ...
    (alt.lang.asm)
  • Re: Nasm, macho and Macos problem
    ... I can't execute a binary file create with NASM (macho output). ... Sistem answers me: ...
    (comp.lang.asm.x86)
  • Re: Forth for Mac OS X Leopard (Intel) - what are the options?
    ... toolchain to assemble and link a working lina binary, ... it, you can execute it. ... (or segments I still do not understand fully the difference - nasm ...
    (comp.lang.forth)
  • Re: which book to start with...?
    ... The CPU *would* execute it, ... find that Nasm puts its name in a .comment section...). ... but i dont understand how the previous test will set the sign flag. ... Not a bad idea - I find Nasm's version of the instruction set reference useful, even though it isn't up-to-date. ...
    (alt.lang.asm)