How to communicate with Linux kernel " The power of assembly programming "
Last updated 2001-07-30 5:36 pm
Library independent "Hello World"
Most of all programmers use printf() or fprintf() to output strings. Of course, they are standard library functions provided by GNU libc. To support output routine in assembly, I created xputchar() function.
xputchar.asm |
|
xputchar() executes "write" system call (Function number is 4) with three arguments. First is file descriptor, second is string buffer pointer, and last is string length. In this program, we use standard output (STDOUT) and specify one as file descriptor. For temporary buffer, I declared a static variable "msgbuf" in .data section. If you want to output a string, you have to create original "strlen()" function.
hello.c |
|
Here is the body of assembly "HelloWorld". It is a simple C language program. Let's create the program.
|
When -s option is specified, ld automatically removes symbol table sections. Completed program is independent of library, and its size is 676 bytes. Finally, we comletely controled Linux kernel without a help of standard environment! Congratulation, but this is the beginning.