我目前正在尝试在我的Trisquel发行版上学习汇编(我猜是在引擎盖下使用Ubuntu?)。 出于某种原因,我被困在创build和执行程序集片段的第一步。
.section data .section text .globl _start _start: movl $1, %eax # syscall for exiting a program movl $0, %ebx # status code to be returned int $0x80
当我尝试组装并链接它来创build可执行文件并运行可执行文件时,我得到如下所示的内容:
> as myexit.s -o myexit.o && ld myexit.o -o myexit > ./myexit bash: ./myexit: cannot execute binary file
我不确定这里到底发生了什么。 在四处search之后,似乎这个错误通常会在尝试在64位操作系统上执行32位可执行文件时popup,反之亦然,而对于我来说则不然。
这里是file
和uname
命令的输出:
$ file myexit myexit: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped $ uname -a Linux user 2.6.35-28-generic #50trisquel2-Ubuntu SMP Tue May 3 00:54:52 UTC 2011 i686 GNU/Linux
有人能帮我理解这里到底发生了什么事吗? 谢谢。
.section text
是不正确的,当您需要您的代码在.text
部分时,创建一个称为text
的部分。 将其替换为:
.data .text .globl _start _start: ...