run an assembly code on ubuntu

mehmet6parmak picture mehmet6parmak · Oct 11, 2010 · Viewed 11.2k times · Source

The code i am trying to run is bellow. I use nasm util to convert it into object file. When i tried to execute it says "can not execute binary file".

I run the command: nasm -f elf -o helloworld.o helloworld.asm

segment .data
msg  db   "Hello, world!",10
len  equ  $ - msg

segment .text
global _start

_start:
   mov  eax,4
   mov  ebx,1
   mov  ecx,msg
   mov  edx,len
   int  80h

   mov  eax,1
   mov  ebx,0
   int  80h

it is my first program in assembly and i did not use ubuntu except compiling some
basic c programs. i need some help thanks all.

Answer

jyz picture jyz · Oct 11, 2010

It works perfectly for me your code.

Did you link the final object file?

Try this: ld helloworld.o -o helloworld