【发布时间】:2017-12-10 05:14:35
【问题描述】:
我一直在查看组装教程,并且正在尝试运行一个 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
然后程序似乎在没有分段错误或错误的情况下运行,但它没有产生任何输出。
我不明白为什么代码不会产生输出,但我想知道在 Windows 上的 Ubuntu 上使用 Bash 是否与它有关?为什么它不产生输出,我该如何解决?
【问题讨论】:
-
您在 64 位可执行文件中使用 32 位系统调用接口这一事实可能与此有关。
-
我听说 Ubuntu-on-Windows 根本不支持 32 位可执行文件;也许他们也不支持 64 位可执行文件中的
int 0x8032 位 ABI。您的代码看起来可以在 Linux 上运行,theint 0x80ABI is supported (but not recommended) in 64-bit mode. -
哦,或者
msg在您的 64 位二进制文件中位于不适合 32 位的地址?这可以解释它,虽然这不是通常的布局。尝试使用strace ./hello或单步与GDB 来查看eax中的错误返回值
标签: linux assembly x86 nasm windows-subsystem-for-linux