Hello-world assembly program in for GNU/Hurd without glibc

191 Views Asked by At

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!
0

There are 0 best solutions below