Hello-World Assembly计划在没有GLIBC的GNU/Hurd中
Hello-world程序的汇编源代码(该程序将打印出恒定消息的stdout,然后成功地退出)的GNU Hurd在i386上看起来像?该程序必须使用GNU Hurd(Mach)系统调用,并且不得使用GLIBC。
用这个问题的另一种方法:用简短的端到端工作代码示例解释和演示,glibc在gnu hurd上(mach)如何实现POSIX库函数 write and em>和 _EXIT 。
作为比较,对于I386上的Linux,它看起来像:
/* File hello.s */
.global _start
.text
_start:
mov $4, %eax /* __NR_write == 4. */
mov $1, %ebx /* STDOUT_FILENO == 1. */
mov $msg, %ecx /* Pointer to message. */
mov $msg_end-msg, %edx /* Message size in bytes. */
int $0x80 /* System call. */
mov $1, %eax /* __NR_exit == 1. */
xor %ebx, %ebx /* EXIT_SUCCESS == 0. */
int $0x80 /* System call. */
msg:
.ascii "Hello, World!\n"
msg_end:
与兼容的GNU Binutils编译:
$ as --32 -march=i386 -o hello.o hello.s
$ ld -m elf_i386 -o hello hello.o
在Linux I386或AMD64上运行:
$ ./hello
Hello, World!
How does the assembly source code of a hello-world program (which prints a constant message to stdout, and then exits successfully) for GNU Hurd on i386 look like? The program must use GNU Hurd (Mach) system calls, and it must not use the glibc.
An alternative way to phrase this question: explain and demonstrate with a short, end-to-end working assembly code example how glibc on GNU Hurd (Mach) implements the POSIX library functions write and _exit.
As a comparison, for Linux on i386, it looks like:
/* File hello.s */
.global _start
.text
_start:
mov $4, %eax /* __NR_write == 4. */
mov $1, %ebx /* STDOUT_FILENO == 1. */
mov $msg, %ecx /* Pointer to message. */
mov $msg_end-msg, %edx /* Message size in bytes. */
int $0x80 /* System call. */
mov $1, %eax /* __NR_exit == 1. */
xor %ebx, %ebx /* EXIT_SUCCESS == 0. */
int $0x80 /* System call. */
msg:
.ascii "Hello, World!\n"
msg_end:
Compile with a compatible GNU Binutils:
$ as --32 -march=i386 -o hello.o hello.s
$ ld -m elf_i386 -o hello hello.o
Run on Linux i386 or amd64:
$ ./hello
Hello, World!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论