请记住,默认情况下,64位OS上的所有内容都倾向于采用64位。您需要确保(a)在适当的地方使用#include的32位版本(b)与32位库的链接以及(c)构建32位可执行文件。如果您显示makefile的内容(如果有的话)或用于构建此示例的命令,则可能会有所帮助。
FWIW我稍微更改了您的代码(_start-> main):
#include <asm/unistd.h>
#include <syscall.h>
#define STDOUT 1
.data
hellostr:
.ascii "hello wolrd\n" ;
helloend:
.text
.globl main
main:
movl $(SYS_write) , %eax //ssize_t write(int fd, const void *buf, size_t count);
movl $(STDOUT) , %ebx
movl $hellostr , %ecx
movl $(helloend-hellostr) , %edx
int $0x80
movl $(SYS_exit), %eax //void _exit(int status);
xorl %ebx, %ebx
int $0x80
ret
并像这样构建它:
$ gcc -Wall test.S -m32 -o test
确认我们具有32位可执行文件:
$ file test
test: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.4, dynamically linked (uses shared libs), not stripped
它似乎运行正常:
$ ./test
hello wolrd