在Ubuntu上运行汇编代码

8

我要翻译的内容如下:

我要运行的代码如下。我使用nasm工具将其转换为目标文件。当我尝试执行它时,会提示“无法执行二进制文件”。

我运行了以下命令: 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

这是我第一次使用汇编语言编写程序,除了编译一些基本的C程序外,我没有使用过Ubuntu。我需要一些帮助,谢谢大家。

1个回答

10

你的代码在我这里运行得非常完美。

你链接了最终的目标文件吗?

试试这个命令:ld helloworld.o -o helloworld


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接