我一直在学习汇编语言的教程,现在尝试运行一个hello world程序。我正在使用Windows上的Ubuntu Bash。
以下是汇编代码:
section .text
global _start ;must be declared for linker (ld)
_start: ;tells linker entry point
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg db 'Hello, world!', 0xa ;string to be printed
len equ $ - msg ;length of the string
我使用以下命令创建可执行文件:
nasm -f elf64 hello.asm -o hello.o
ld -o hello hello.o -m elf_x86_64
我使用以下命令运行它:
./hello
程序似乎没有出现分段错误或错误,但是它没有产生任何输出。
我无法弄清楚代码为什么不会产生输出,但我想知道是否使用Bash on Ubuntu on Windows有关系?为什么它不产生输出,我该如何解决?
int 0x80
调用也不被支持。您的代码看起来可以在Linux上运行,在那里,int 0x80
调用在64位模式下是被支持的(但不建议使用)。 - Peter Cordesmsg
位于一个地址上,该地址不适合32位,在您的64位二进制文件中?这可以解释,尽管这不是通常的布局。尝试使用strace ./hello
或使用GDB单步执行以查看eax
中的错误返回值。 - Peter Cordes